Skip to content

Build your personal knowledge base with Trilium Notes

fix(tab_manager): correct order when reopening split pane

SiriusXT5a5d242ea00d
diff --git a/apps/client/src/components/tab_manager.ts b/apps/client/src/components/tab_manager.ts
index 517ff2501d..127ec30b7d 100644
--- a/apps/client/src/components/tab_manager.ts
+++ b/apps/client/src/components/tab_manager.ts
@@ -647,7 +647,32 @@ export default class TabManager extends Component {
...this.noteContexts.slice(-noteContexts.length),
...this.noteContexts.slice(lastClosedTab.position, -noteContexts.length)
];
- this.noteContextReorderEvent({ ntxIdsInOrder: ntxsInOrder.map((nc) => nc.ntxId).filter((id) => id !== null) });
+
+ // Update mainNtxId if the restored pane is the main pane in the split pane
+ const { oldMainNtxId, newMainNtxId } = (() => {
+ if (noteContexts.length !== 1) {
+ return { oldMainNtxId: undefined, newMainNtxId: undefined };
+ }
+
+ const mainNtxId = noteContexts[0]?.mainNtxId;
+ const index = this.noteContexts.findIndex(c => c.ntxId === mainNtxId);
+
+ // No need to update if the restored position is after mainNtxId
+ if (index === -1 || lastClosedTab.position > index) {
+ return { oldMainNtxId: undefined, newMainNtxId: undefined };
+ }
+
+ return {
+ oldMainNtxId: this.noteContexts[index].ntxId ?? undefined,
+ newMainNtxId: noteContexts[0]?.ntxId ?? undefined
+ };
+ })();
+
+ this.triggerCommand("noteContextReorder", {
+ ntxIdsInOrder: ntxsInOrder.map((nc) => nc.ntxId).filter((id) => id !== null),
+ oldMainNtxId,
+ newMainNtxId
+ });
let mainNtx = noteContexts.find((nc) => nc.isMainContext());
if (mainNtx) {
diff --git a/apps/client/src/widgets/containers/split_note_container.ts b/apps/client/src/widgets/containers/split_note_container.ts
index 90e77c0211..c370cc4eb2 100644
--- a/apps/client/src/widgets/containers/split_note_container.ts
+++ b/apps/client/src/widgets/containers/split_note_container.ts
@@ -181,12 +181,14 @@ export default class SplitNoteContainer extends FlexContainer<SplitNoteWidget> {
splitService.delNoteSplitResizer(ntxIds);
}
- contextsReopenedEvent({ ntxId, afterNtxId }: EventData<"contextsReopened">) {
- if (ntxId === undefined || afterNtxId === undefined) {
- // no single split reopened
- return;
+ contextsReopenedEvent({ ntxId, mainNtxId, tabPosition, afterNtxId }: EventData<"contextsReopened">) {
+ if (ntxId !== undefined && afterNtxId !== undefined) {
+ this.$widget.find(`[data-ntx-id="${ntxId}"]`).insertAfter(this.$widget.find(`[data-ntx-id="${afterNtxId}"]`));
+ } else if (mainNtxId && tabPosition >= 0) {
+ const contexts = appContext.tabManager.noteContexts;
+ const beforeNtxId = contexts.find(c => c.mainNtxId === mainNtxId)?.ntxId || null;
+ this.$widget.find(`[data-ntx-id="${mainNtxId}"]`).insertBefore(this.$widget.find(`[data-ntx-id="${beforeNtxId}"]`));
}
- this.$widget.find(`[data-ntx-id="${ntxId}"]`).insertAfter(this.$widget.find(`[data-ntx-id="${afterNtxId}"]`));
}
async refresh() {