Skip to content

Commit c048134

Browse files
committed
Fix(panels): panel shortcuts leave a pane alone when it is not showing a note
With Trash, Tasks, Help or an asset in the active tab, Cmd+2, Cmd+3 and Shift+Cmd+C (and the calendar toggle) still flipped that pane's Connections, Outline, Comments and Calendar. There is no panel to see on those tabs, so nothing appeared to happen, and the change turned up on the next note instead: a panel you never asked for was open, or the one you had open was gone. The four toggle listeners now only act when the pane's active tab is a note. The test is the kind of tab, not whether content has loaded, so a shortcut pressed while a note is still opening is kept. Closing the right panel with its own shortcut is unchanged, since closing something you cannot see does no harm.
1 parent eb09088 commit c048134

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

‎packages/app-core/src/components/EditorPane.tsx‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ import {
273273
import { resolveCommentAnchor, selectionToCommentAnchor } from '../lib/comments'
274274
import { ZEN_OPEN_EDITOR_CONTEXT_MENU_EVENT } from '../lib/keyboard-context-menu'
275275
import { armMiddleClickPasteGuard } from '../lib/middle-click-paste-guard'
276+
import { isWorkspaceVirtualTabPath } from '../lib/workspace-tabs'
276277
import {
277278
CALENDAR_PANEL_CLOSED,
278279
calendarPanelOnNote,
@@ -1062,16 +1063,24 @@ export function EditorPane({ pane }: { pane: PaneLeaf }): JSX.Element {
10621063
})
10631064
}, [focusedPanel, setConnectionPreview, setFocusedPanel])
10641065

1066+
// The panel shortcuts act on the note this pane is showing. On a view tab
1067+
// (Trash, Tasks, Help, an asset) there is no panel to see, and the toggle
1068+
// used to flip the pane's panels anyway, so they turned up on the next note
1069+
// without having been asked for. Keyed on the kind of tab, not on loaded
1070+
// content, so a shortcut pressed while a note is still loading is kept.
1071+
const panelShortcutsApply =
1072+
isActive && activeTab != null && !isWorkspaceVirtualTabPath(activeTab)
1073+
10651074
// ⌘2 toggles the connections panel — only the active pane responds so
10661075
// the shortcut targets the pane the user is currently working in.
10671076
useEffect(() => {
1068-
if (!isActive) return
1077+
if (!panelShortcutsApply) return
10691078
const handler = (): void => {
10701079
toggleConnectionsPanel()
10711080
}
10721081
window.addEventListener('zen:toggle-connections', handler)
10731082
return () => window.removeEventListener('zen:toggle-connections', handler)
1074-
}, [isActive, toggleConnectionsPanel])
1083+
}, [panelShortcutsApply, toggleConnectionsPanel])
10751084

10761085
// Mirror `set clipboard=unnamed`: when enabled, Vim yank/delete/change also
10771086
// copy to the system clipboard, and `p` / `P` paste from it. The patch is
@@ -1128,32 +1137,32 @@ export function EditorPane({ pane }: { pane: PaneLeaf }): JSX.Element {
11281137
// `zen:toggle-outline` — routed only to the active pane, same pattern
11291138
// as the connections toggle.
11301139
useEffect(() => {
1131-
if (!isActive) return
1140+
if (!panelShortcutsApply) return
11321141
const handler = (): void => {
11331142
toggleOutlinePanel()
11341143
}
11351144
window.addEventListener('zen:toggle-outline', handler)
11361145
return () => window.removeEventListener('zen:toggle-outline', handler)
1137-
}, [isActive, toggleOutlinePanel])
1146+
}, [panelShortcutsApply, toggleOutlinePanel])
11381147

11391148
useEffect(() => {
1140-
if (!isActive) return
1149+
if (!panelShortcutsApply) return
11411150
const handler = (): void => {
11421151
toggleCommentsPanel()
11431152
}
11441153
window.addEventListener('zen:toggle-comments', handler)
11451154
return () => window.removeEventListener('zen:toggle-comments', handler)
1146-
}, [isActive, toggleCommentsPanel])
1155+
}, [panelShortcutsApply, toggleCommentsPanel])
11471156

11481157
// `zen:toggle-calendar` — same active-pane routing as the panels above.
11491158
useEffect(() => {
1150-
if (!isActive) return
1159+
if (!panelShortcutsApply) return
11511160
const handler = (): void => {
11521161
toggleCalendarPanel()
11531162
}
11541163
window.addEventListener('zen:toggle-calendar', handler)
11551164
return () => window.removeEventListener('zen:toggle-calendar', handler)
1156-
}, [isActive, toggleCalendarPanel])
1165+
}, [panelShortcutsApply, toggleCalendarPanel])
11571166

11581167
// `zen:close-right-panel` — Esc (when a right panel is focused) or the
11591168
// "Close right panel" command dismiss whichever right-hand panel is open in

0 commit comments

Comments
 (0)