Skip to content

Build your personal knowledge base with Trilium Notes

tree fixes

zadam119d7367da5f
diff --git a/libraries/codemirror/addon/lint/eslint.js b/libraries/codemirror/addon/lint/eslint.js
index 7fdb345534..ce04f0bc46 100644
--- a/libraries/codemirror/addon/lint/eslint.js
+++ b/libraries/codemirror/addon/lint/eslint.js
@@ -28,7 +28,7 @@
}
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
return [];
}
diff --git a/src/public/javascripts/desktop.js b/src/public/javascripts/desktop.js
index f1ff1f57b4..bfc6948394 100644
--- a/src/public/javascripts/desktop.js
+++ b/src/public/javascripts/desktop.js
@@ -118,7 +118,9 @@ $("body").on("click", "a.external", function () {
if (utils.isElectron()) {
require('electron').ipcRenderer.on('create-day-sub-note', async function(event) {
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);
diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.js
index 5b0ae6997f..dff16a3036 100644
--- a/src/public/javascripts/services/tree.js
+++ b/src/public/javascripts/services/tree.js
@@ -80,6 +80,18 @@ async function expandToNote(notePath, 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 = {}) {
utils.assertArguments(notePath);
@@ -104,18 +116,17 @@ async function getNodeFromPath(notePath, expand = false, expandOpts = {}) {
parentNode.setExpanded(true, expandOpts);
}
- let foundChildNode = null;
+ let foundChildNode = findChildNode(parentNode, childNoteId);
- for (const childNode of parentNode.getChildren()) {
- if (childNode.data.noteId === childNoteId) {
- foundChildNode = childNode;
- break;
- }
- }
+ if (!foundChildNode) { // note might be recently created so we'll force reload and try again
+ await parentNode.load(true);
- if (!foundChildNode) {
- console.error(`Can't find node for child node of noteId=${childNoteId} for parent of noteId=${parentNode.data.noteId} and hoistedNoteId=${hoistedNoteId}`);
- return;
+ foundChildNode = findChildNode(parentNode, childNoteId);
+
+ if (!foundChildNode) {
+ 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;
+ }
}
parentNode = foundChildNode;
@@ -317,7 +328,8 @@ async function getSomeNotePath(note) {
const parents = await cur.getParentNotes();
if (!parents.length) {
- infoService.throwError("Can't find parents for " + cur);
+ infoService.throwError("Can't find parents for ", cur);
+ return;
}
cur = parents[0];
@@ -900,5 +912,6 @@ export default {
loadTreeCache,
expandToNote,
getNodeFromPath,
- resolveNotePath
+ resolveNotePath,
+ getSomeNotePath
};
\ No newline at end of file