tree fixes

This commit is contained in:
zadam 2019-05-19 18:21:29 +02:00
parent ddb99a0917
commit 119d7367da
3 changed files with 29 additions and 14 deletions

View File

@ -28,7 +28,7 @@
} }
async function validatorJavaScript(text, options) { async function validatorJavaScript(text, options) {
if (glob.getActiveNote().mime === 'application/json') { if (glob.getActiveNote() == null || glob.getActiveNote().mime === 'application/json') {
// eslint doesn't seem to validate pure JSON well // eslint doesn't seem to validate pure JSON well
return []; return [];
} }

View File

@ -118,7 +118,9 @@ $("body").on("click", "a.external", function () {
if (utils.isElectron()) { if (utils.isElectron()) {
require('electron').ipcRenderer.on('create-day-sub-note', async function(event) { require('electron').ipcRenderer.on('create-day-sub-note', async function(event) {
const todayNote = await dateNoteService.getTodayNote(); const todayNote = await dateNoteService.getTodayNote();
const node = await treeService.expandToNote(todayNote.noteId); const notePath = await treeService.getSomeNotePath(todayNote);
const node = await treeService.expandToNote(notePath);
await noteDetailService.openEmptyTab(false); await noteDetailService.openEmptyTab(false);

View File

@ -80,6 +80,18 @@ async function expandToNote(notePath, expandOpts) {
return await getNodeFromPath(notePath, true, expandOpts); return await getNodeFromPath(notePath, true, expandOpts);
} }
function findChildNode(parentNode, childNoteId) {
let foundChildNode = null;
for (const childNode of parentNode.getChildren()) {
if (childNode.data.noteId === childNoteId) {
foundChildNode = childNode;
break;
}
}
return foundChildNode;
}
async function getNodeFromPath(notePath, expand = false, expandOpts = {}) { async function getNodeFromPath(notePath, expand = false, expandOpts = {}) {
utils.assertArguments(notePath); utils.assertArguments(notePath);
@ -104,19 +116,18 @@ async function getNodeFromPath(notePath, expand = false, expandOpts = {}) {
parentNode.setExpanded(true, expandOpts); parentNode.setExpanded(true, expandOpts);
} }
let foundChildNode = null; let foundChildNode = findChildNode(parentNode, childNoteId);
for (const childNode of parentNode.getChildren()) { if (!foundChildNode) { // note might be recently created so we'll force reload and try again
if (childNode.data.noteId === childNoteId) { await parentNode.load(true);
foundChildNode = childNode;
break; foundChildNode = findChildNode(parentNode, childNoteId);
}
}
if (!foundChildNode) { if (!foundChildNode) {
console.error(`Can't find node for child node of noteId=${childNoteId} for parent of noteId=${parentNode.data.noteId} and hoistedNoteId=${hoistedNoteId}`); messagingService.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; return;
} }
}
parentNode = foundChildNode; parentNode = foundChildNode;
} }
@ -317,7 +328,8 @@ async function getSomeNotePath(note) {
const parents = await cur.getParentNotes(); const parents = await cur.getParentNotes();
if (!parents.length) { if (!parents.length) {
infoService.throwError("Can't find parents for " + cur); infoService.throwError("Can't find parents for ", cur);
return;
} }
cur = parents[0]; cur = parents[0];
@ -900,5 +912,6 @@ export default {
loadTreeCache, loadTreeCache,
expandToNote, expandToNote,
getNodeFromPath, getNodeFromPath,
resolveNotePath resolveNotePath,
getSomeNotePath
}; };