Skip to content

Commit 5a5d242

Browse files
committed
fix(tab_manager): correct order when reopening split pane
1 parent 4afea27 commit 5a5d242

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

apps/client/src/components/tab_manager.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,32 @@ export default class TabManager extends Component {
647647
...this.noteContexts.slice(-noteContexts.length),
648648
...this.noteContexts.slice(lastClosedTab.position, -noteContexts.length)
649649
];
650-
this.noteContextReorderEvent({ ntxIdsInOrder: ntxsInOrder.map((nc) => nc.ntxId).filter((id) => id !== null) });
650+
651+
// Update mainNtxId if the restored pane is the main pane in the split pane
652+
const { oldMainNtxId, newMainNtxId } = (() => {
653+
if (noteContexts.length !== 1) {
654+
return { oldMainNtxId: undefined, newMainNtxId: undefined };
655+
}
656+
657+
const mainNtxId = noteContexts[0]?.mainNtxId;
658+
const index = this.noteContexts.findIndex(c => c.ntxId === mainNtxId);
659+
660+
// No need to update if the restored position is after mainNtxId
661+
if (index === -1 || lastClosedTab.position > index) {
662+
return { oldMainNtxId: undefined, newMainNtxId: undefined };
663+
}
664+
665+
return {
666+
oldMainNtxId: this.noteContexts[index].ntxId ?? undefined,
667+
newMainNtxId: noteContexts[0]?.ntxId ?? undefined
668+
};
669+
})();
670+
671+
this.triggerCommand("noteContextReorder", {
672+
ntxIdsInOrder: ntxsInOrder.map((nc) => nc.ntxId).filter((id) => id !== null),
673+
oldMainNtxId,
674+
newMainNtxId
675+
});
651676

652677
let mainNtx = noteContexts.find((nc) => nc.isMainContext());
653678
if (mainNtx) {

apps/client/src/widgets/containers/split_note_container.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,14 @@ export default class SplitNoteContainer extends FlexContainer<SplitNoteWidget> {
181181
splitService.delNoteSplitResizer(ntxIds);
182182
}
183183

184-
contextsReopenedEvent({ ntxId, afterNtxId }: EventData<"contextsReopened">) {
185-
if (ntxId === undefined || afterNtxId === undefined) {
186-
// no single split reopened
187-
return;
184+
contextsReopenedEvent({ ntxId, mainNtxId, tabPosition, afterNtxId }: EventData<"contextsReopened">) {
185+
if (ntxId !== undefined && afterNtxId !== undefined) {
186+
this.$widget.find(`[data-ntx-id="${ntxId}"]`).insertAfter(this.$widget.find(`[data-ntx-id="${afterNtxId}"]`));
187+
} else if (mainNtxId && tabPosition >= 0) {
188+
const contexts = appContext.tabManager.noteContexts;
189+
const beforeNtxId = contexts.find(c => c.mainNtxId === mainNtxId)?.ntxId || null;
190+
this.$widget.find(`[data-ntx-id="${mainNtxId}"]`).insertBefore(this.$widget.find(`[data-ntx-id="${beforeNtxId}"]`));
188191
}
189-
this.$widget.find(`[data-ntx-id="${ntxId}"]`).insertAfter(this.$widget.find(`[data-ntx-id="${afterNtxId}"]`));
190192
}
191193

192194
async refresh() {

0 commit comments

Comments
 (0)