Fix word wrap misalignment at the end of the document (#948) - #957
Open
Xiao Di (xiaoditx) wants to merge 1 commit into
Open
Xiao Di (xiaoditx) wants to merge 1 commit into
Xiao Di (xiaoditx) wants to merge 1 commit into
Conversation
Author
|
@microsoft-github-policy-service agree |
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.
Problem
Fixes #948. With word wrap enabled, the cursor and line-number margin drift on the last line of a document: an extra empty row appears below the text. Moving into a word on the last line can trigger it; repeated Left/Right adds more rows, and debug builds may hit:
assertion failed: cursor.visual_pos.y <= self.stats.visual_linesRoot cause
The word-wrap lookahead in
measure_forward()did not stop at the end of the text, so it re-measured the last cluster until it falsely reported a wrap. It also moved words wider than a row as whole words, although hard wrap already handled them. Forward cursor movement could also measure from the cursor's current wrapped position instead of the line start, so the same logical position could map to different visual positions.Changes
measurement.rs: stop lookahead at end of text; only wrap whole words that fit on a row.buffer/mod.rs: re-anchor forward cursor moves to line start when word wrap is enabled; count the extra rowrender()uses when the cursor sits on the wrap column at end of document; update line stats before validating the cursor inedit_end().Verification
cargo test --workspaceall green.cargo fmt --all -- --checkno diff for changed files.cargo clippy -p edit --all-targetsno new warnings.Notes
I filed this issue a few weeks ago; since it had not been picked up, I fixed it with AI assistance and manually reviewed the changes. My English is not very good, and I left many comments mostly unchanged, so some may be inaccurate or verbose. Please point out anything that should be corrected during review.