fix: prevent errors when focus gets lost on new tag
This commit is contained in:
@@ -175,6 +175,9 @@ class TagsViewCtrl extends PureViewCtrl<{}, TagState> {
|
|||||||
}
|
}
|
||||||
const noteCounts: NoteCounts = {};
|
const noteCounts: NoteCounts = {};
|
||||||
for (const tag of allTags) {
|
for (const tag of allTags) {
|
||||||
|
if (tag === this.state.templateTag) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (tag.isSmartTag()) {
|
if (tag.isSmartTag()) {
|
||||||
/** Other smart tags do not contain counts */
|
/** Other smart tags do not contain counts */
|
||||||
if (tag.isAllTag) {
|
if (tag.isAllTag) {
|
||||||
@@ -295,6 +298,9 @@ class TagsViewCtrl extends PureViewCtrl<{}, TagState> {
|
|||||||
|
|
||||||
async saveTag($event: Event, tag: SNTag) {
|
async saveTag($event: Event, tag: SNTag) {
|
||||||
($event.target! as HTMLInputElement).blur();
|
($event.target! as HTMLInputElement).blur();
|
||||||
|
if (!this.titles[tag.uuid]?.length) {
|
||||||
|
return this.undoCreateTag(tag);
|
||||||
|
}
|
||||||
if (this.getState().templateTag) {
|
if (this.getState().templateTag) {
|
||||||
return this.saveNewTag();
|
return this.saveNewTag();
|
||||||
} else {
|
} else {
|
||||||
@@ -302,6 +308,16 @@ class TagsViewCtrl extends PureViewCtrl<{}, TagState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async undoCreateTag(tag: SNTag) {
|
||||||
|
await this.setState({
|
||||||
|
templateTag: undefined,
|
||||||
|
editingTag: undefined,
|
||||||
|
selectedTag: this.appState.selectedTag,
|
||||||
|
tags: this.state.tags.filter(existingTag => existingTag !== tag)
|
||||||
|
});
|
||||||
|
delete this.titles[tag.uuid];
|
||||||
|
}
|
||||||
|
|
||||||
async saveTagRename(tag: SNTag) {
|
async saveTagRename(tag: SNTag) {
|
||||||
const newTitle = this.titles[tag.uuid] || '';
|
const newTitle = this.titles[tag.uuid] || '';
|
||||||
if (newTitle.length === 0) {
|
if (newTitle.length === 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user