Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: disable all kinds of navigation in pinned tabs

Abdullah Attab636b09a9678
diff --git a/apps/web/src/components/editor/action-bar.tsx b/apps/web/src/components/editor/action-bar.tsx
index c35d2245b..ba96ea3b1 100644
--- a/apps/web/src/components/editor/action-bar.tsx
+++ b/apps/web/src/components/editor/action-bar.tsx
@@ -410,15 +410,7 @@ const TabStrip = React.memo(function TabStrip() {
)
: undefined
}
- onPin={() => {
- const tabs = useEditorStore.getState().tabs.slice();
- const index = tabs.findIndex((t) => t.id === tab.id);
- tabs[index].pinned = !tabs[index].pinned;
- tabs.sort((a, b) =>
- a.pinned === b.pinned ? 0 : a.pinned ? -1 : 1
- );
- useEditorStore.setState({ tabs });
- }}
+ onPin={() => useEditorStore.getState().pinTab(tab.id)}
/>
);
}}
diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.ts
index 5877219b0..4f6c29fed 100644
--- a/apps/web/src/stores/editor-store.ts
+++ b/apps/web/src/stores/editor-store.ts
@@ -650,15 +650,19 @@ class EditorStore extends BaseStore<EditorStore> {
tabs,
activateSession,
activeTabId,
+ getActiveTab,
rehydrateSession,
getTabsForNote,
addTab
} = this.get();
const noteId = typeof noteOrId === "string" ? noteOrId : noteOrId.id;
const oldTabForNote = options.force ? null : getTabsForNote(noteId).at(0);
- const tabId = options.openInNewTab
- ? addTab(getId())
- : oldTabForNote?.id || activeTabId || addTab(getId());
+ const activeTab = getActiveTab();
+ const tabId =
+ // if a tab is pinned then always open a new tab.
+ options.openInNewTab || activeTab?.pinned
+ ? addTab(getId())
+ : oldTabForNote?.id || activeTabId || addTab(getId());
const tab = tabs.find((t) => t.id === tabId);
const activeSession = tab && getSession(tab.sessionId);
@@ -1188,6 +1192,26 @@ class EditorStore extends BaseStore<EditorStore> {
return id;
};
+ pinTab = (tabId: string) => {
+ const { tabs: _tabs, activeTabId } = this.get();
+ const tabs = _tabs.slice();
+ const index = tabs.findIndex((t) => t.id === tabId);
+ if (index === -1) return;
+
+ tabs[index].pinned = !tabs[index].pinned;
+ const disableNavigation = activeTabId === tabId && tabs[index].pinned;
+
+ useEditorStore.setState({
+ tabs: tabs.sort((a, b) =>
+ a.pinned === b.pinned ? 0 : a.pinned ? -1 : 1
+ ),
+ canGoBack: disableNavigation ? false : tabSessionHistory.canGoBack(tabId),
+ canGoForward: disableNavigation
+ ? false
+ : tabSessionHistory.canGoForward(tabId)
+ });
+ };
+
focusTab = (tabId: string | undefined, sessionId?: string) => {
if (!tabId) return;
@@ -1195,14 +1219,14 @@ class EditorStore extends BaseStore<EditorStore> {
if (history.includes(tabId)) history.splice(history.indexOf(tabId), 1);
history.push(tabId);
+ const tab = this.get().tabs.find((t) => t.id === tabId);
this.set({
activeTabId: tabId,
- canGoBack: tabSessionHistory.canGoBack(tabId),
- canGoForward: tabSessionHistory.canGoForward(tabId)
+ canGoBack: !tab?.pinned && tabSessionHistory.canGoBack(tabId),
+ canGoForward: !tab?.pinned && tabSessionHistory.canGoForward(tabId)
});
- sessionId =
- sessionId || this.get().tabs.find((t) => t.id === tabId)?.sessionId;
+ sessionId = sessionId || tab?.sessionId;
if (sessionId) this.rehydrateSession(sessionId);
};
}