Skip to content

ALI-2565: Select part of Quick View's text from the keyboard (F7 caret mode) - #67

Merged
michaelaguiar merged 3 commits into
mainfrom
aliasbot/ali-2565-caret-mode
Dec 4, 2026
Merged

michaelaguiar merged 3 commits into
mainfrom
aliasbot/ali-2565-caret-mode

Conversation

@michaelaguiar

Copy link
Copy Markdown
Member

Fixes ALI-2565.

In Quick View, the mouse could select any part of a text or Markdown preview, but the keyboard could only select all of it (Ctrl+A). Someone who can't use a mouse had no way to copy just a line or a word. This adds a caret mode, as browsers have.

Behaviour

  • On and off: F7 puts a caret at the start of the first line wholly in view. F7 or Escape turns it off, and that Escape doesn't close Quick View.
  • Moving:
    • Arrows move by a character or a line (a line break is one step).
    • Ctrl+Left/Right move by a word, as text fields do.
    • Home/End go to the ends of the screen line, and Ctrl+Home/End to the ends of the document.
    • Up/Down keep a goal column.
  • Selecting: Shift with any of these extends the selection from where it started. Ctrl+C copies, as before. A click moves the caret, and a drag carries it.
  • Scrolling: the view scrolls to keep the caret in sight.
  • Text kinds: wrapped lines, tabs (one step, drawn at the tab stop) and Markdown tables (cell by cell, with rules skipped). It builds on ALI-2545: Select and copy text in Quick View #53's Layout offsets in docview.rs. The caret resets when a new document arrives.
  • Screen readers:
    • "Caret mode on" and "Caret mode off" are announced.
    • While it's on, focus moves to a read-only paragraph node holding the caret's line, offering the Text interface.
    • Moves within a line send caret-moved and selection-changed events; moving to another line sends caret-moved, so the line is read there.
    • Table cells are read with a space between them.
  • README: the Preview section describes caret mode, and the mouse selection from ALI-2545: Select and copy text in Quick View #53.

Cost

There's no blink timer. Nothing is computed or drawn while caret mode is off, and a key press repaints only the old and new caret lines, or the document area when the selection or scroll changes.

10,000-line text, headless sway:

main this branch
Idle wake-ups with a document showing 0/s 0/s
Idle wake-ups with caret mode on — 0/s
Caret Down, paint — 0.15–0.16 ms (p95 0.42–0.45 when it scrolls)
Caret Right, paint — 0.12 ms
Shift+Down (scrolling a line), paint 0.33 ms 0.33–0.34 ms

Contrast

design/build --check now lists the caret pairs at a 3:1 minimum. The lowest across all 11 themes:

Pair Lowest
Foreground on border 6.85:1
On-selection on selection 6.20:1 (Ayu Dark)

One miss, and its fix: in Osaka Jade, foreground equals selection (1.00:1), so no single caret colour works. At a selection edge, the caret is half foreground on the background side and half on-selection on the selection side, so each half has its own background's contrast. The caret is 2 px wide (new token doc-caret), since it doesn't blink.

Judgement calls (made overnight, for Mike to confirm)

  • Home/End: they go to the ends of the screen line, as browsers do with caret browsing.
  • Word moves: they follow text fields, with letters, digits and _ as word characters, the same as double-click.
  • Steps: they go by Unicode character, not grapheme cluster.
  • Selection: arrows without Shift drop it, and turning caret mode off keeps it.
  • Page Up/Down and the wheel: they scroll without moving the caret.
  • Screen readers: caret moves requested by a screen reader (SetCaretOffset, SetSelection) are refused, and character boxes are not given.

Checks

  • Unit tests pass, with new ones for character, word, line, Home/End, wrapped-line, tab and table movement, the copied text, repainting only on change, caret pixels, a click, and the screen-reader snapshot and announcements.
  • Clippy: 0 warnings. design/build --check passes.
  • e2e: 125 checks pass. The new caret_mode_selects_part_of_a_line_from_the_keyboard selects "hunter2" and a table row from the keyboard, reads them back with wl-paste in light and dark, and fails against main. The screen-reader check now covers the announcements and the caret line's events.
  • Not checked: Mike hasn't tried a dev build yet (~/.cache/gannet-dev/gannet-caret), and it hasn't been heard with real Orca (only the scripted AT-SPI client). This stays a draft until he's tried it.

…aret mode)

F7 in a text or Markdown preview turns on a caret at the start of the first
line in view. The arrows move it by a character or a line, Ctrl+Left and
Ctrl+Right by a word, Home and End to the ends of the line as it's shown,
and Ctrl+Home and Ctrl+End to the ends of the text. Shift with any of them
selects from where it started, and Ctrl+C copies as before. Up and Down keep
a column across shorter lines. A click moves the caret. F7 or Escape turns
it off; Escape then doesn't close the window. The view scrolls to keep the
caret in sight.

The caret works on wrapped lines (the end of one is drawn at its end), tabs
(one step, drawn at the stop) and Markdown tables (cell by cell, rules
passed over), using the layout's offsets, so what's selected copies as a
drag's selection does.

It costs nothing while off, and doesn't blink: no timer runs, and a key
repaints only the caret's old and new lines, or the document when the
selection or the scroll changes. Idle wakeups with it on stay at 0.

The caret is 2 px (new token doc-caret), in foreground on the background
and on-selection on the selection, half in each at the selection's edge, so
each half has 3:1 on what it's on in every theme: foreground and
on-selection are the same as selection and base in Osaka Jade, so a single
colour couldn't. The token file lists the pairs.

A screen reader hears "Caret mode on" and "Caret mode off", and in caret
mode the keyboard is on a read-only paragraph holding the caret's line
(table cells apart by spaces), with its caret and selection. Within a line
the caret and selection events are sent as a field's are; moving to another
line is a new line rather than an edit, so the caret is said to move and
the line is read from there.
@michaelaguiar

Copy link
Copy Markdown
Member Author

Review round 1. The code-review skill ran, along with design/build --check and the caret tests. No P1. Being fixed:

  • P2: after a double or triple click in caret mode, the caret stays mid-word, so Shift+arrow extends from the wrong anchor and the copy differs from the highlight. The caret will go to the selection's end, with the anchor at its start.
  • P2: a held Escape leaves caret mode and then the key repeat closes Quick View. Repeats right after leaving caret mode will be swallowed.
  • P3:
    • Ctrl+A in caret mode resets the anchor;
    • Previous, Next and Close drop their arrow and Escape shortcut hints while caret mode is on;
    • relayout keeps the wrap-end position, scrolls to the caret and bumps the AT-SPI line generation;
    • an empty line's caret starts at the block's indent;
    • README notes on caret mode's arrows and Shift+Up/Down.
  • Declined (P3): Page Up/Down and the wheel scrolling the caret off screen. It's usual caret-browsing behaviour, now noted in the README.

Confirmed fine:

  • line and document ends, multibyte characters, tabs, goal columns and table rules;
  • scrolling;
  • the reset on a new document;
  • no key conflicts;
  • tokens and the split caret contrast;
  • no timer;
  • the read-only AT-SPI paragraph, which refuses edits and leaves nothing behind on close.

… closing

- A double or triple click in caret mode left the caret where the pointer
  was, inside the word or line, so Shift+arrow grew the selection from the
  wrong end. The caret now goes to the word's or line's end, and Shift grows
  it from its start. What a screen reader is told of the line's selection
  comes from the same place (CaretMode::other_end).
- Escape held after it turned caret mode off closed the window on the next
  repeat. Repeats after that are swallowed; a second press still closes.
- Ctrl+A in caret mode puts the caret at the end, so Shift gives some back.
- In caret mode, Previous file, Next file and Close no longer give Left,
  Right and Escape as their keys, as those move the caret and leave the mode.
- A resize keeps the caret at a wrapped line's end if it was there, scrolls
  it into view, and tells a screen reader the line laid out again is a new
  one rather than an edit.
- On an empty list item, quote or code line, the caret is where its text
  would start, not at the page's margin.
- The README says the arrows don't go to other files in caret mode, Shift+Up
  and Shift+Down select, and Page Up, Page Down and the wheel scroll without
  moving the caret.
@michaelaguiar

Copy link
Copy Markdown
Member Author

Round 1 fixes are in 5e28679.

  • P2, double or triple click: fixed. A word or line press in caret mode puts the caret at the selection's end and the anchor at its start, through a shared CaretMode::other_end that the screen-reader line uses too. The claim that Ctrl+C copied something other than the highlight was wrong: it copies text_sel, which is what's highlighted. Test.
  • P2, held Escape: fixed. Repeats are swallowed right after Escape leaves caret mode, and a fresh press still closes. Test.
  • P3:
    • Ctrl+A puts the caret at the end with the anchor at 0;
    • Previous, Next and Close offer no keys while caret mode is on;
    • relayout keeps the wrap-end position, scrolls to the caret through one shared caret_scroll, and counts layouts into the screen-reader line generation;
    • an empty list item or quote line places the caret where its text would start;
    • README notes.
      Tests for each.
  • Declined: Page Up/Down and the wheel, as noted in round 1.

Unit tests: 527 + 441 + 5. Clippy: 0 warnings. design/build --check passes. e2e: 125 pass.

@michaelaguiar

Copy link
Copy Markdown
Member Author

Review round 2 (by hand, narrow check of 5e28679): no P1 or P2. Each round 1 fix holds:

  • caret_escaped can't swallow a deliberate Escape;
  • the layout count changes the screen-reader line generation only on relayout, so moves within a line still send caret-moved;
  • a single click behaves as before.

Being fixed (P3, all scrolling):

  • a double or triple click scrolls to the caret at the selection's end;
  • Ctrl+A no longer jumps the view to the end of the document;
  • relayout keeps the caret in view only if it was in view before, so a wheel-scrolled view isn't snapped back.

…om it

- A double or triple click in caret mode scrolls the caret, now at the end
  of the word or line, into view, so a wrapped paragraph ending below the
  window shows its end.
- Ctrl+A in caret mode puts the caret at the end but leaves the view where
  it is, as Page Down and the wheel do; the next arrow goes to the caret.
- A resize keeps the caret in view only if it was in view before, so a view
  scrolled away from it with the wheel stays where it was.
@michaelaguiar

Copy link
Copy Markdown
Member Author

Round 2 fixes are in 880b53a.

  • A double or triple click scrolls the caret at the selection's end into view.
  • Ctrl+A leaves the view where it is. Test.
  • Relayout keeps the view on the caret only if the caret's line was in view before it. Test.

The review loop stops here: round 2 had only P3s, and these three are small scrolling changes covered by tests. Unit tests: 529 + 441 + 5. Clippy: 0 warnings. design/build --check passes. e2e: 125 pass.

@michaelaguiar
michaelaguiar marked this pull request as ready for review December 4, 2026 14:00
@michaelaguiar
michaelaguiar merged commit 0aeb420 into main Dec 4, 2026
3 checks passed
@michaelaguiar
michaelaguiar deleted the aliasbot/ali-2565-caret-mode branch December 4, 2026 15:56
@michaelaguiar michaelaguiar mentioned this pull request Dec 4, 2026
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.

1 participant