Skip to content

rust: end a zero-width selection on Enter and deletes - #2048

Open
simonklee wants to merge 2 commits into
mainfrom
harden/608-rust-textarea-click-zero-width-selection
Open

simonklee wants to merge 2 commits into
mainfrom
harden/608-rust-textarea-click-zero-width-selection

Conversation

@simonklee

Copy link
Copy Markdown
Member

A click in a Rust Textarea or Input starts a selection with the same anchor and focus. Enter,
Backspace, Delete and the word deletes only ended a selection that had a width, so the zero-width one
stayed, and the editor view does not follow the cursor while a selection exists. In a one-row
Textarea, a click then Enter left the cursor on the row below the visible one, and later frames did
not bring it back. OpenCode's Rust prompt is such a Textarea.

These edits now end any selection, as Core's edits do. A click still keeps its native anchor, so a
drag that starts from it extends from the same text as before.

Tested with a table over click, a drag back to the start, and a drag over text, each followed by
each of the five edits, in a one-row Textarea (the text, and that the cursor is inside the view),
plus a line of only a combining mark and a one-character selection.

A click in a Textarea starts a selection with the same anchor and
focus. Enter, Backspace, Delete and the word deletes only ended a
selection that had a width, so the zero-width one stayed, and the
editor view does not follow the cursor while a selection exists. In a
one-row Textarea, a click then Enter left the cursor on row 2 with row
1 showing, and later frames did not bring it back.

These edits now end any selection, as Core's edits do. A click still
keeps its native anchor, so a drag that starts from it is unchanged.

Issue: 608
Two breaks of the edit rule passed every test. Deleting natively on
the click's empty selection removed a line that holds only a combining
mark (U+0301), since native deletes such zero-cell bytes on an empty
range. Treating a one-cell selection as empty made Delete remove the
character after it. A click then Enter on that line, and Delete on a
one-character selection, now check both.

Tests are over the line budget (+44 on this branch, target negative):
this is the first Rust test that checks the editor view follows the
cursor after a mouse gesture, and there was no Textarea mouse table to
extend, so it is one new table test.

Issue: 608
@simonklee
simonklee requested a review from kommander as a code owner November 12, 2026 12:54

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.

1 participant