Repository navigation
feat: add a caret and text selection to the type tool - #38
Conversation
55a84a2 to
b5dd781
Compare
IAmJSD
left a comment
There was a problem hiding this comment.
Reviewed by Claude (Fable 5) on Astrid's behalf. Traced the byte-range bookkeeping through wrapping, trailing newlines and the wrap-boundary ambiguity (resolved correctly on both the caret and selection-rect sides), confirmed the overlay maps layout space to canvas exactly, and verified the keymap interplay with #36's contexts. The engine-side LineSpan/caret_at design — caret geometry from the same pass as glyph placement — is the right shape. Tests assert real geometry and semantics. I rebased the branch onto current main (the #36 commit dropped out as already merged; the test-module conflict with #46 was a clean stitch, both sides kept) and re-ran the app, type-tool and text-engine suites — all green. Non-blocking follow-ups: the hand-rolled grapheme test doesn't treat ZWJ sequences/flag pairs atomically (backspace can leave a dangling ZWJ); backspace at offset 0 still sets changed=true, so a fresh session ends as an empty layer plus a no-op edit instead of taking the #46 discard path (pre-existing); and the selection overlay re-runs full layout per line per paint — worth one call returning layout + caret positions. Merging.
b5dd781 to
1d87277
Compare
fixes #37
stacked on #36 — without that change the keystrokes never reach the tool, because gpui dispatches a matching binding before the element's
on_key_downand actions stop propagation by default. this branch contains that commit as its base; review it second.adds
caretandanchorbyte offsets to the editing session, and with them: arrows, home/end, delete, ctrl+arrow word jumps, shift-selection, ctrl+a to select the text, insertion at the caret, and typing over a selection to replace it. backspace and delete move by grapheme rather than bychar, so an accented letter or an emoji goes in one press.the engine side is the part worth looking at closely.
layoutnow carries each line's byte range through to the caller, andcaret_at/line_spansare built from that same pass, so glyph placement and caret placement cannot disagree. that is what the old overlay got wrong, and it is why the caret drifted a little further on every line.ctrl+a is the only shortcut the tool claims. everything else with a modifier still falls through to the app.
verified by hand in a running window as well as by the tests: caret moves and inserts mid-word, ctrl+a selects the text, typing replaces the selection, shift-arrow extends it, ctrl+arrow jumps words, up/down keep the column, escape still exits.
not in scope: clipboard (ctrl+c/v over text needs workspace plumbing), click-to-place-caret, and ime. all still open.