Skip to content

fix(state): account for dropped break whitespace in wrapped selection - #172

Open
Shaisolaris wants to merge 1 commit into
AMythicDev:mainfrom
Shaisolaris:fix-wrapped-selection-offset
Open

Shaisolaris wants to merge 1 commit into
AMythicDev:mainfrom
Shaisolaris:fix-wrapped-selection-offset

Conversation

@Shaisolaris

Copy link
Copy Markdown

With line wrapping on, copying a selection that starts on a wrapped row copies text shifted to the left of what is highlighted.

selection_col_in_line finds where a wrapped row starts in its line by summing the character counts of the preceding rows from textwrap::wrap. textwrap drops the whitespace at each break, so for text with spaces the result is one character short for every preceding row. For example, with cols = 6, hello world foo wraps to hello / world / foo. Selecting from the start of world to the end of foo highlights world foo but copies world f.

This finds each wrapped row in the line in order and uses its real starting offset. The highlighting (selection_bounds_for_row) already works on display rows and is unchanged.

Testing:

  • Added extract_selection_across_wrapped_rows_with_spaces. It fails on main (left: Some(" world f")) and passes with this change. The existing extract_selection_across_wrapped_rows (text without spaces) still passes.
  • cargo test --all-features --lib -- --skip pager::tests: 116 passed. I skipped pager::tests because basic_dynamic_paging needs a real terminal in my environment.
  • cargo fmt --check is clean, and cargo clippy --all-features --all-targets reports the same 4 warnings as main, all in files this PR does not touch.

The change does not address terminal column width for wide (e.g. CJK) characters, where a screen column and a character index differ. That is a separate issue.

@Shaisolaris
Shaisolaris force-pushed the fix-wrapped-selection-offset branch from f4482f9 to 30eed2f Compare October 31, 2026 10:43
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