From bcabe5786ff03f2b3affcfe36f0696d78597ebc9 Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 27 Oct 2021 21:32:03 +0200 Subject: [PATCH] fix ordering of note contexts, fixes #2283 --- package-lock.json | 2 +- src/public/app/services/note_context.js | 8 +++++++- src/public/app/services/tab_manager.js | 2 +- src/public/app/widgets/containers/split_note_container.js | 8 +++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 28cdc0e0c..6f8a27ad7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "trilium", - "version": "0.48.2", + "version": "0.48.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/public/app/services/note_context.js b/src/public/app/services/note_context.js index c92f52e21..95d814086 100644 --- a/src/public/app/services/note_context.js +++ b/src/public/app/services/note_context.js @@ -71,7 +71,13 @@ class NoteContext extends Component { getMainContext() { if (this.mainNtxId) { - return appContext.tabManager.getNoteContextById(this.mainNtxId); + try { + return appContext.tabManager.getNoteContextById(this.mainNtxId); + } + catch (e) { + this.mainNtxId = null; + return this; + } } else { return this; diff --git a/src/public/app/services/tab_manager.js b/src/public/app/services/tab_manager.js index 8ecbb546a..45971e331 100644 --- a/src/public/app/services/tab_manager.js +++ b/src/public/app/services/tab_manager.js @@ -353,7 +353,7 @@ export default class TabManager extends Component { const order = {}; let i = 0; - for (const ntxId in ntxIdsInOrder) { + for (const ntxId of ntxIdsInOrder) { order[ntxId] = i++; } diff --git a/src/public/app/widgets/containers/split_note_container.js b/src/public/app/widgets/containers/split_note_container.js index e01272b59..7042c7ff0 100644 --- a/src/public/app/widgets/containers/split_note_container.js +++ b/src/public/app/widgets/containers/split_note_container.js @@ -37,6 +37,12 @@ export default class SplitNoteContainer extends FlexContainer { } async openNewNoteSplitEvent({ntxId, notePath}) { + if (!ntxId) { + logError("empty ntxId!"); + + ntxId = appContext.tabManager.getActiveMainContext().ntxId; + } + const noteContext = await appContext.tabManager.openEmptyTab(null, 'root', appContext.tabManager.getActiveMainContext().ntxId); // remove the original position of newly created note context @@ -46,7 +52,7 @@ export default class SplitNoteContainer extends FlexContainer { // insert the note context after the originating note context ntxIds.splice(ntxIds.indexOf(ntxId) + 1, 0, noteContext.ntxId); - this.triggerCommand("noteContextReorder", ntxIds); + this.triggerCommand("noteContextReorder", {ntxIdsInOrder: ntxIds}); // move the note context rendered widget after the originating widget this.$widget.find(`[data-ntx-id="${noteContext.ntxId}"]`)