(direction: PaneDirection)
| 152 | * focused so keyboard input lands in the new pane's CodeMirror view. |
| 153 | */ |
| 154 | export function focusPaneInDirection(direction: PaneDirection): boolean { |
| 155 | const state = useStore.getState() |
| 156 | const rects = getPaneRects() |
| 157 | // Treat the pinned reference pane as the "currently focused" pane |
| 158 | // when its CodeMirror is the active element — geometric nav picks up |
| 159 | // from where the cursor actually lives, not from activePaneId. |
| 160 | const activeEl = document.activeElement as HTMLElement | null |
| 161 | const inPinned = |
| 162 | activeEl?.closest(`[data-pane-id="${PINNED_REF_PANE_ID}"]`) != null |
| 163 | const currentId = inPinned ? PINNED_REF_PANE_ID : state.activePaneId |
| 164 | const targetId = findNeighborPaneId(rects, currentId, direction) |
| 165 | if (!targetId) return false |
| 166 | if (targetId === PINNED_REF_PANE_ID) { |
| 167 | state.setFocusedPanel('editor') |
| 168 | requestAnimationFrame(focusPinnedRefDom) |
| 169 | return true |
| 170 | } |
| 171 | state.setActivePane(targetId) |
| 172 | state.setFocusedPanel('editor') |
| 173 | requestAnimationFrame(() => { |
| 174 | useStore.getState().editorViewRef?.focus() |
| 175 | }) |
| 176 | return true |
| 177 | } |
| 178 | |
| 179 | /** Focus the editor pane at the left or right edge of the editor area. Used |
| 180 | * when crossing in from an edge panel (sidebar / note list / connections) so |
no test coverage detected