Skip to content

Commit 4447585

Browse files
committed
feat(split): allow closing any split pane
1 parent fbc2ffa commit 4447585

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

apps/client/src/widgets/buttons/close_pane_button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default function ClosePaneButton() {
88
const [ isEnabled, setIsEnabled ] = useState(false);
99

1010
function refresh() {
11-
setIsEnabled(!!(noteContext && !!noteContext.mainNtxId));
11+
setIsEnabled(!!noteContext);
1212
}
1313

1414
useTriliumEvent("noteContextReorder", refresh);

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,23 @@ export default class SplitNoteContainer extends FlexContainer<SplitNoteWidget> {
100100
}
101101

102102
async closeThisNoteSplitCommand({ ntxId }: CommandListenerData<"closeThisNoteSplit">) {
103-
if (ntxId) {
104-
await appContext.tabManager.removeNoteContext(ntxId);
103+
if (!ntxId) return;
104+
const contexts = appContext.tabManager.noteContexts;
105+
106+
const currentIndex = contexts.findIndex((c) => c.ntxId === ntxId);
107+
if (currentIndex === -1) return;
108+
109+
const isRemoveMainContext = !contexts[currentIndex].mainNtxId;
110+
if (isRemoveMainContext && currentIndex + 1 <= contexts.length) {
111+
const ntxIds = contexts.map((c) => c.ntxId).filter((c) => !!c) as string[];
112+
this.triggerCommand("noteContextReorder", {
113+
ntxIdsInOrder: ntxIds,
114+
oldMainNtxId: ntxId,
115+
newMainNtxId: ntxIds[currentIndex + 1]
116+
});
105117
}
118+
119+
await appContext.tabManager.removeNoteContext(ntxId);
106120
}
107121

108122
async moveThisNoteSplitCommand({ ntxId, isMovingLeft }: CommandListenerData<"moveThisNoteSplit">) {

0 commit comments

Comments
 (0)