fixed duplicated notes after creating into a folder which wasn't yet loaded

This commit is contained in:
zadam 2019-07-06 13:14:33 +02:00
parent 2b44f3bc76
commit ddf381f92d

View file

@ -635,18 +635,18 @@ async function createNote(node, parentNoteId, target, extraOptions = {}) {
};
if (target === 'after') {
console.log(`Appending node...`); // to debug duplicated nodes
await node.appendSibling(newNode).setActive(true);
}
else if (target === 'into') {
if (!node.getChildren() && node.isFolder()) {
// folder is not loaded - load will bring up the note since it was already put into cache
await node.load(true);
await node.setExpanded();
}
console.log(`Adding node as child...`); // to debug duplicated nodes
node.addChildren(newNode);
else {
node.addChildren(newNode);
}
await node.getLastChild().setActive(true);
@ -742,10 +742,12 @@ utils.bindShortcut('ctrl+o', async () => {
async function createNoteInto() {
const node = getActiveNode();
await createNote(node, node.data.noteId, 'into', {
isProtected: node.data.isProtected,
saveSelection: true
});
if (node) {
await createNote(node, node.data.noteId, 'into', {
isProtected: node.data.isProtected,
saveSelection: true
});
}
}
async function checkFolderStatus(node) {