fix: reflect tag deletion from synced note
This commit is contained in:
@@ -112,6 +112,8 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
|
|||||||
public editorValues: EditorValues = {}
|
public editorValues: EditorValues = {}
|
||||||
onEditorLoad?: () => void
|
onEditorLoad?: () => void
|
||||||
|
|
||||||
|
private tags: SNTag[] = [];
|
||||||
|
|
||||||
private removeAltKeyObserver?: any
|
private removeAltKeyObserver?: any
|
||||||
private removeTrashKeyObserver?: any
|
private removeTrashKeyObserver?: any
|
||||||
private removeTabObserver?: any
|
private removeTabObserver?: any
|
||||||
@@ -165,6 +167,7 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
|
|||||||
this.statusTimeout = undefined;
|
this.statusTimeout = undefined;
|
||||||
(this.onPanelResizeFinish as any) = undefined;
|
(this.onPanelResizeFinish as any) = undefined;
|
||||||
(this.editorMenuOnSelect as any) = undefined;
|
(this.editorMenuOnSelect as any) = undefined;
|
||||||
|
this.tags = [];
|
||||||
super.deinit();
|
super.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +189,7 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
|
|||||||
if (isPayloadSourceRetrieved(source!)) {
|
if (isPayloadSourceRetrieved(source!)) {
|
||||||
this.editorValues.title = note.title;
|
this.editorValues.title = note.title;
|
||||||
this.editorValues.text = note.text;
|
this.editorValues.text = note.text;
|
||||||
this.reloadTagsString();
|
this.reloadTags();
|
||||||
}
|
}
|
||||||
if (!this.editorValues.title) {
|
if (!this.editorValues.title) {
|
||||||
this.editorValues.title = note.title;
|
this.editorValues.title = note.title;
|
||||||
@@ -285,7 +288,7 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
|
|||||||
this.editorValues.title = note.title;
|
this.editorValues.title = note.title;
|
||||||
this.editorValues.text = note.text;
|
this.editorValues.text = note.text;
|
||||||
this.reloadEditor();
|
this.reloadEditor();
|
||||||
this.reloadTagsString();
|
this.reloadTags();
|
||||||
this.reloadPreferences();
|
this.reloadPreferences();
|
||||||
this.reloadStackComponents();
|
this.reloadStackComponents();
|
||||||
this.reloadNoteTagsComponent();
|
this.reloadNoteTagsComponent();
|
||||||
@@ -312,20 +315,8 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
|
|||||||
streamItems() {
|
streamItems() {
|
||||||
this.removeTagsObserver = this.application.streamItems(
|
this.removeTagsObserver = this.application.streamItems(
|
||||||
ContentType.Tag,
|
ContentType.Tag,
|
||||||
(items) => {
|
() => {
|
||||||
if (!this.note) {
|
this.reloadTags();
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (const tag of items) {
|
|
||||||
if (
|
|
||||||
!this.editorValues.tagsInputValue ||
|
|
||||||
tag.deleted ||
|
|
||||||
tag.hasRelationshipWithItem(this.note)
|
|
||||||
) {
|
|
||||||
this.reloadTagsString();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -790,8 +781,31 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async reloadTagsString() {
|
async reloadTags() {
|
||||||
|
if (!this.note) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const tags = this.appState.getNoteTags(this.note);
|
const tags = this.appState.getNoteTags(this.note);
|
||||||
|
if (tags.length !== this.tags.length) {
|
||||||
|
this.reloadTagsString(tags);
|
||||||
|
} else {
|
||||||
|
/** Check that all tags are the same */
|
||||||
|
for (let i = 0; i < tags.length; i++) {
|
||||||
|
const localTag = this.tags[i];
|
||||||
|
const tag = tags[i];
|
||||||
|
if (
|
||||||
|
tag.title !== localTag.title ||
|
||||||
|
tag.uuid !== localTag.uuid
|
||||||
|
) {
|
||||||
|
this.reloadTagsString(tags);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.tags = tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async reloadTagsString(tags: SNTag[]) {
|
||||||
const string = SNTag.arrayToDisplayString(tags);
|
const string = SNTag.arrayToDisplayString(tags);
|
||||||
await this.flushUI();
|
await this.flushUI();
|
||||||
this.editorValues.tagsInputValue = string;
|
this.editorValues.tagsInputValue = string;
|
||||||
@@ -872,7 +886,7 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
this.application.sync();
|
this.application.sync();
|
||||||
this.reloadTagsString();
|
this.reloadTags();
|
||||||
}
|
}
|
||||||
|
|
||||||
async onPanelResizeFinish(width: number, left: number, isMaxWidth: boolean) {
|
async onPanelResizeFinish(width: number, left: number, isMaxWidth: boolean) {
|
||||||
|
|||||||
Reference in New Issue
Block a user