fix delete note function just work one time, closes #1101

This commit is contained in:
zadam
2020-06-10 23:43:59 +02:00
parent 2d92b4931a
commit 910bda860c
5 changed files with 31 additions and 62 deletions

View File

@@ -743,17 +743,20 @@ export default class NoteTreeWidget extends TabAwareWidget {
}
/** @return {FancytreeNode} */
async getNodeFromPath(notePath, expand = false) {
async getNodeFromPath(notePath, expand = false, logErrors = true) {
utils.assertArguments(notePath);
const hoistedNoteId = hoistedNoteService.getHoistedNoteId();
/** @var {FancytreeNode} */
let parentNode = null;
const runPath = await treeService.getRunPath(notePath);
const runPath = await treeService.getRunPath(notePath, logErrors);
if (!runPath) {
console.error("Could not find run path for notePath:", notePath);
if (logErrors) {
console.error("Could not find run path for notePath:", notePath);
}
return;
}
@@ -790,7 +793,10 @@ export default class NoteTreeWidget extends TabAwareWidget {
foundChildNode = this.findChildNode(parentNode, childNoteId);
if (!foundChildNode) {
ws.logError(`Can't find node for child node of noteId=${childNoteId} for parent of noteId=${parentNode.data.noteId} and hoistedNoteId=${hoistedNoteId}, requested path is ${notePath}`);
if (logErrors) {
ws.logError(`Can't find node for child node of noteId=${childNoteId} for parent of noteId=${parentNode.data.noteId} and hoistedNoteId=${hoistedNoteId}, requested path is ${notePath}`);
}
return;
}
}
@@ -817,8 +823,8 @@ export default class NoteTreeWidget extends TabAwareWidget {
}
/** @return {FancytreeNode} */
async expandToNote(notePath) {
return this.getNodeFromPath(notePath, true);
async expandToNote(notePath, logErrors = true) {
return this.getNodeFromPath(notePath, true, logErrors);
}
updateNode(node) {
@@ -1026,7 +1032,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
}
if (activeNotePath) {
let node = await this.expandToNote(activeNotePath);
let node = await this.expandToNote(activeNotePath, false);
if (node && node.data.noteId !== activeNoteId) {
// if the active note has been moved elsewhere then it won't be found by the path
@@ -1042,7 +1048,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
}
else {
// this is used when original note has been deleted and we want to move the focus to the note above/below
node = await this.expandToNote(nextNotePath);
node = await this.expandToNote(nextNotePath, false);
if (node) {
await appContext.tabManager.getActiveTabContext().setNote(nextNotePath);