Skip to content

Build your personal knowledge base with Trilium Notes

client/tab bar: prevent the split of a pinned tab note to be closed

Adorian Doran2f140966d179
diff --git a/apps/client/src/components/tab_manager.ts b/apps/client/src/components/tab_manager.ts
index c5d87b41a5..fea026f656 100644
--- a/apps/client/src/components/tab_manager.ts
+++ b/apps/client/src/components/tab_manager.ts
@@ -421,9 +421,10 @@ export default class TabManager extends Component {
return false;
}
- if (noteContextToRemove.isMainContext() && noteContextToRemove.pinned) {
- // pinned tabs can't be closed — they must be unpinned first. This single guard also
- // makes Ctrl-W, middle-click and the bulk "close others/right/all" commands skip them.
+ if (noteContextToRemove.pinned) {
+ // a pinned context can't be closed — the tab must be unpinned first. This single guard
+ // makes Ctrl-W, middle-click, the bulk "close others/right/all" commands and the
+ // pinned note's split pane all refuse to close it.
return false;
}
diff --git a/apps/client/src/widgets/buttons/close_pane_button.tsx b/apps/client/src/widgets/buttons/close_pane_button.tsx
index 7ffae309da..7d23467b32 100644
--- a/apps/client/src/widgets/buttons/close_pane_button.tsx
+++ b/apps/client/src/widgets/buttons/close_pane_button.tsx
@@ -10,10 +10,11 @@ export default function ClosePaneButton() {
function refresh() {
const isMainOfSomeContext = appContext.tabManager.noteContexts.some(c => c.mainNtxId === ntxId);
- setIsEnabled(!!(noteContext && (!!noteContext.mainNtxId || isMainOfSomeContext)));
+ // the pane showing a pinned note can't be closed (unpin the tab first); other panes stay closeable
+ setIsEnabled(!!(noteContext && !noteContext.pinned && (!!noteContext.mainNtxId || isMainOfSomeContext)));
}
- useTriliumEvents(["noteContextRemoved", "noteContextReorder", "newNoteContextCreated"], refresh);
+ useTriliumEvents(["noteContextRemoved", "noteContextReorder", "newNoteContextCreated", "tabPinStateChanged"], refresh);
useEffect(refresh, [ntxId]);
return (
diff --git a/apps/client/src/widgets/containers/split_note_container.ts b/apps/client/src/widgets/containers/split_note_container.ts
index c006775a4e..e2b755e458 100644
--- a/apps/client/src/widgets/containers/split_note_container.ts
+++ b/apps/client/src/widgets/containers/split_note_container.ts
@@ -113,6 +113,12 @@ export default class SplitNoteContainer extends FlexContainer<SplitNoteWidget> {
const currentIndex = contexts.findIndex((c) => c.ntxId === ntxId);
if (currentIndex === -1) return;
+ // the pane showing a pinned note can't be closed (unpin the tab first). Bail before the
+ // demote/reorder below, which would otherwise strip the main context of its pinned state.
+ if (contexts[currentIndex].pinned) {
+ return;
+ }
+
const isRemoveMainContext = contexts[currentIndex].isMainContext();
if (isRemoveMainContext && currentIndex + 1 < contexts.length) {
const ntxIds = contexts.map((c) => c.ntxId).filter((c) => !!c) as string[];