Skip to content

fix(markdown): copy the characters a drag selection highlights - #563

Merged
Tryanks merged 1 commit into
mainfrom
fix/markdown-copy-last-char
Oct 1, 2026
Merged

Tryanks merged 1 commit into
mainfrom
fix/markdown-copy-last-char

Conversation

@Tryanks

@Tryanks Tryanks commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Changed behaviour

Dragging to select Markdown text and copying dropped the last character whenever the drag ended on the right half of that character.

gpui-base paints a character as selected when the selection covers its horizontal midpoint. Copy resolved each endpoint through MarkdownSelectionAdapter::runs_at, which used TextLayout::index_for_position; that returns the start of the character under the pointer. So the copied range ended one character before the painted one, and a start on a character's right half copied one character more than was painted.

runs_at now resolves to the nearest character boundary with nearest_boundary, which follows gpui-base's band test (midpoint, and half a line height as the width of a character that ends its row). No new abstraction beyond that private helper.

Test

markdown::state::tests::drag_copies_exactly_the_highlighted_text sweeps the drag end across "Hello world" pixel by pixel and asserts the copied text equals the painted selection. Without the fix it fails at x = 5 (highlighted "H", copied "").

Checks run

  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets --locked -- -D warnings
  • cargo nextest run --workspace --locked — 978 passed, 5 skipped

Not exercised by hand in the running app; mobile/Web checks left to CI.

A drag ending on the right half of a character highlights it, but copy
resolved the end with TextLayout::index_for_position, which returns the
start of the character under the pointer, so the last highlighted
character was dropped (and a start on a character's right half copied
one extra). Resolve endpoint offsets to the nearest character boundary
using gpui-base's midpoint band rule.
@Tryanks
Tryanks merged commit 9d20bb3 into main Oct 1, 2026
7 checks passed
@Tryanks
Tryanks deleted the fix/markdown-copy-last-char branch October 1, 2026 16:32
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