Repository navigation
fix(markdown): copy the characters a drag selection highlights - #563
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 usedTextLayout::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_atnow resolves to the nearest character boundary withnearest_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_textsweeps 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 --checkcargo clippy --workspace --all-targets --locked -- -D warningscargo nextest run --workspace --locked— 978 passed, 5 skippedNot exercised by hand in the running app; mobile/Web checks left to CI.