Skip to content

feat: add a caret and text selection to the type tool - #38

Merged
IAmJSD merged 1 commit into
Infrawrench:mainfrom
ProdigyRahul:feat/text-caret
Aug 27, 2026
Merged

IAmJSD merged 1 commit into
Infrawrench:mainfrom
ProdigyRahul:feat/text-caret

Conversation

@ProdigyRahul

Copy link
Copy Markdown
Contributor

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_down and actions stop propagation by default. this branch contains that commit as its base; review it second.

adds caret and anchor byte 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 by char, so an accented letter or an emoji goes in one press.

the engine side is the part worth looking at closely. layout now carries each line's byte range through to the caller, and caret_at/line_spans are 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.

before

after

@IAmJSD IAmJSD left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@IAmJSD
IAmJSD merged commit ee69617 into Infrawrench:main Aug 27, 2026
3 checks passed
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.

the type tool has no caret, so text cannot be edited once typed

2 participants