Skip to content

Adjust the book selection with Shift+arrow keys - #773

Open
WildHagai wants to merge 1 commit into
kdroidFilter:masterfrom
WildHagai:feat/shift-arrow-selection
Open

WildHagai wants to merge 1 commit into
kdroidFilter:masterfrom
WildHagai:feat/shift-arrow-selection

Conversation

@WildHagai

Copy link
Copy Markdown

What

With text selected in the book reader, Shift+arrows fine-tune the selection like a text editor. The anchor end stays fixed and only the focus end moves.

Key bindings

Keys Moves the focus
Shift+Left / Shift+Right one character (a letter together with its nikud and teamim)
Ctrl+Shift+Left / Ctrl+Shift+Right one word (abbreviations such as רש״י count as one word)
Shift+Up / Shift+Down one visual line, keeping the same horizontal position across a run of presses
  • Works on any selection: a drag, a double-click or a Shift+click. A drag is adjusted from the end you dragged to.
  • Moves continue into the next or previous book line, including lines scrolled out of view, and the view scrolls to keep the focus visible.
  • With nothing selected, plain and Shift arrows behave as before (line navigation and scrolling).
  • Ctrl+Shift+Up/Down and Alt or Meta combinations are left alone, so the window's Ctrl+Alt+Left/Right still works.

RTL behavior

The arrows follow the screen. In a right-to-left (Hebrew) line, Left moves toward the end of the text (the next letter, which sits to its left) and Right toward the start. In a left-to-right line it is the reverse. The direction comes from each line's own text, so books that mix Hebrew and Latin lines feel natural in both. Within a line, moves follow the order of the text, as a text editor's cursor does across a short run in the other direction. This is documented in towardsEnd in SelectionMotion.kt.

Implementation

  • SelectionMotion.kt (new): the character, word and visual-line moves, and the Shift+arrow handler.
  • BookSelection.kt: the selection now keeps an anchor and a focus. It also records the layout and position of each line on screen, hides Compose's own highlight under the reader's selection, and makes Ctrl+C wait briefly for a selection the keys just moved.
  • BookContentView.kt: the Shift+arrow handler runs before the plain arrow handling, and the view scrolls to keep the focus visible.
  • BookContentScreen.kt: after a run of key presses, the selected text is looked up once the keys pause for 80 ms instead of on every press.

Tests

  • SelectionMotionTest (new): direction, characters with nikud, words and abbreviations, crossing lines, visual lines.
  • BookSelectionTest: anchor and focus, starting from each kind of selection, no selection after a plain click.
  • ShiftArrowSelectionUiTest (new): the keys move the focus in Hebrew text, and arrows are left to the view when nothing is selected.
  • The existing selection and keyboard tests (ShiftClickSelectionUiTest, UnplacedSelectionUiTest, LineSelectionIntegrationTest, BookContentKeyboardUiTest) still pass. 60 tests pass in all, and ktlintCheck is clean.
  • Not yet tried by hand in the running app.

🤖 Generated with Claude Code

With text selected in the book reader, Shift+arrows move the selection's
focus end as in a text editor, the anchor end staying fixed:

- Shift+Left/Right: one character (a letter with its nikud/teamim)
- Ctrl+Shift+Left/Right: one word
- Shift+Up/Down: one visual line, keeping a goal column across a run

Left/Right follow the screen: in a right-to-left (Hebrew) line Left
moves toward the end of the text and Right toward its start; in a
left-to-right line the reverse. The direction is taken from the
focus's line, from its own text.

Only an existing selection (a drag, a double click, a Shift+click) is
adjusted: without one, plain and Shift arrows keep scrolling/moving by
line as before, and Ctrl+Alt/Meta combinations stay the window's.

Signed-off-by: Chagai Yisroel Wild <wildhagai@puzzlesoft.co.il>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants