Fix arrow key navigation in study block table cells#102
Conversation
|
@hendriebeats what does this do? |
@boxyoman I could have done a better job explaining it. On desktop when your cursor is in the study block section and you use the up and down arrow keys to move from block to block, instead of moving to what would seem like the natural position of the cursor above, it will jump to the left or right. This is because the whey prosemirror structures the nodes, by default the cursor can only move to the next node. This makes it so when you move up and down within the study block sections, the cursor stays horizontally positioned in a way that makes sense |
@hendriebeats I don't have that problem at all when I'm using it. |
Yeah it's been so annoying for me ever since we first made it. I wonder if it's a Chrome only thing. There's two other things to note about the implementation:
|
…table cells ProseMirror's default up/down navigation follows document order, causing the cursor to jump to the wrong column in the two-column study block layout. The plugin intercepts arrow keys at cell boundaries and navigates visually, preserving horizontal cursor position via coordinate probing. Also fixes a boundary-position bug where posAtCoords could return a position between block siblings, causing TextSelection to throw. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
bba0ed1 to
ba7956a
Compare
- Use window.base prefix for pencil icon src in StudyBlocksView - Remove commented-out dead code (img/x.svg) from SidebarSections - Add .claude and CLAUDE.md to .gitignore - Simplify resolveLinePos call in navigateToTarget (pass dir directly) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
ProseMirror's default
ArrowUp/ArrowDownnavigation follows document order, which causes the cursor to jump to the wrong column when navigating the two-column study block table layout. This PR adds a keymap plugin that intercepts arrow keys at cell boundaries and navigates visually instead, usingcoordsAtPos/posAtCoordsto preserve horizontal cursor position.Details
StudyBlockArrowPlugin.tsThe plugin only activates when the cursor is at the top or bottom edge of a cell (
atCellEdge), using a 5px tolerance on the Y coordinate to distinguish single-line vs multi-line cells. When at an edge, it callsfindAdjacentCellto locate the target cell in document structure, thenresolveLinePosto probe the correct position within that cell at the same X coordinate as the current cursor.findAdjacentCellhandles two distinct row types:generalStudyBlockrows (header/body columns) — navigates by row index, preserving which column (header or body) the cursor is inquestionsrows — navigates betweenquestionText/questionAnswerwithin a question, then across questions, then out to the nextgeneralStudyBlockrownavigateOutOfStudyBlockshandles the case where there's no adjacent cell in the given direction — it exits thestudyBlocksnode into the preceding sibling (e.g.bibleText) or the next section.handleSectionHeaderUpcovers one additional edge case: pressingArrowUpfrom the first line of asectionHeaderwhen the previous section ends with astudyBlocksnode. ProseMirror's default would land at the end of the last cell (right column), but this handler probes the correct column by X coordinate.Editor.tsxRegisters
studyBlockArrowPluginin the plugin list and fixes the pencil iconsrcto usewindow.basefor correct path resolution in all deployment contexts.