Skip to content

Fix mouse caret positioning and gutter selection with word wrap#114

Merged
tig merged 5 commits into
developfrom
copilot/fix-mouse-caret-positioning
May 14, 2026
Merged

Fix mouse caret positioning and gutter selection with word wrap#114
tig merged 5 commits into
developfrom
copilot/fix-mouse-caret-positioning

Conversation

Copilot AI commented May 14, 2026

Copy link
Copy Markdown
Contributor
  • Fix MousePositionToOffset in Editor.Mouse.cs to use the wrap map when WordWrap is enabled
  • Add BuildVisualLineForSegment for lightweight offset hit-testing of wrap segments
  • Add 3 integration tests for mouse click with word wrap enabled
  • Fix ViewRowToLineNumber to use wrap map when WordWrap is enabled
  • Fix LineNumberGutter.OnDrawingContent to render correctly with word wrap (blank for continuation rows)
  • Add 2 failing tests for gutter click/drag with word wrap — confirmed they fail before fix, pass after
  • Address CR feedback: use WrapMapEntry.SegmentIndex for continuation detection instead of prevLineNumber comparison (fixes scrolled-to-continuation edge case)
  • Add IsViewRowFirstWrapSegment and GetTotalVisualRows helpers
  • Add integration test verifying gutter continuation row renders as blank
  • Build and run all tests (411 unit + 140 integration) — all pass
  • Run validation

Copilot AI assigned Copilot and tig May 14, 2026
Copilot AI linked an issue May 14, 2026 that may be closed by this pull request
MousePositionToOffset now uses the wrap map when WordWrap is true,
correctly resolving visual rows to the right document line segment.
Previously it used GetVisibleLineNumbers which maps rows 1:1 to
document lines, ignoring that a single line may span multiple visual
rows when wrapped.

Adds BuildVisualLineForSegment for lightweight offset hit-testing
without drawing attributes, and three integration tests covering
clicks on wrapped rows, past-segment-end snapping, and first-row
clicks with wrap enabled.

Agent-Logs-Url: https://github.com/gui-cs/Editor/sessions/681b65ff-92f8-4c48-b849-4da7193f8690

Co-authored-by: tig <585482+tig@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix mouse caret positioning issue with wordwrap Fix mouse caret positioning with word wrap May 14, 2026
Copilot AI requested a review from tig May 14, 2026 02:57
Copilot finished work on behalf of tig May 14, 2026 02:57
@tig

tig commented May 14, 2026

Copy link
Copy Markdown
Member

@copilot selectkion using line numbers is still not right. again, ensure there are tests that fail before fixing.

Copilot AI and others added 2 commits May 14, 2026 03:43
ViewRowToLineNumber now uses the wrap map when WordWrap is enabled,
correctly resolving visual rows (including wrap-continuation rows) to
the right document line number. Previously it used GetVisibleLineNumbers
which maps rows 1:1 to document lines, causing gutter clicks on
continuation rows to select the wrong line.

LineNumberGutter.OnDrawingContent also updated to use the wrap-aware
ViewRowToLineNumber and show blank for continuation rows instead of
repeating (or showing wrong) line numbers.

Two new tests: gutter click on wrap-continuation row, and gutter drag
across wrapped rows.

Agent-Logs-Url: https://github.com/gui-cs/Editor/sessions/87e391ef-f643-4b93-a072-52b1f23725ee

Co-authored-by: tig <585482+tig@users.noreply.github.com>
…ant ViewRowToLineNumber call

Agent-Logs-Url: https://github.com/gui-cs/Editor/sessions/87e391ef-f643-4b93-a072-52b1f23725ee

Co-authored-by: tig <585482+tig@users.noreply.github.com>

Copilot AI commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot selectkion using line numbers is still not right. again, ensure there are tests that fail before fixing.

Fixed in c0fce33. ViewRowToLineNumber now uses the wrap map when WordWrap is enabled, so gutter clicks on wrap-continuation rows resolve to the correct document line. LineNumberGutter.OnDrawingContent also updated to show blank for continuation rows instead of wrong/repeated line numbers.

Added two tests that fail before the fix:

  • GutterClick_On_Wrap_Continuation_Selects_Correct_Line — was selecting line 2 instead of line 1
  • GutterDrag_Across_Wrap_Rows_Selects_Correct_Lines — drag across wrapped rows

Copilot AI changed the title Fix mouse caret positioning with word wrap Fix mouse caret positioning and gutter selection with word wrap May 14, 2026
Copilot finished work on behalf of tig May 14, 2026 03:46
@tig
tig marked this pull request as ready for review May 14, 2026 03:48

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3bf3b10346

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/Terminal.Gui.Editor/LineNumberGutter.cs Outdated
@tig

tig commented May 14, 2026

Copy link
Copy Markdown
Member

@copilot see CR feedback and address as appropriate.

Address CR feedback: LineNumberGutter.OnDrawingContent now uses
IsViewRowFirstWrapSegment (checks WrapMapEntry.SegmentIndex == 0)
instead of comparing with the previous row's line number. The old
approach failed when the viewport was scrolled so row 0 was a
continuation segment, because prevLineNumber started at -1.

Also adds GetTotalVisualRows for correct past-end-of-document blank
detection, and a new integration test verifying gutter rendering
shows blank for continuation rows.

Agent-Logs-Url: https://github.com/gui-cs/Editor/sessions/3215bcaf-60b9-4a9d-9a41-17efadb6b671

Co-authored-by: tig <585482+tig@users.noreply.github.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Copilot AI commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot see CR feedback and address as appropriate.

Addressed in 5c870be. The Codex CR identified that LineNumberGutter.OnDrawingContent used prevLineNumber comparison to detect continuation rows, which fails when the viewport is scrolled so row 0 is already a continuation segment.

Fix: Added IsViewRowFirstWrapSegment() which checks WrapMapEntry.SegmentIndex == 0 from the wrap map metadata instead. Also added GetTotalVisualRows() for correct past-end-of-document blank detection, and a new integration test verifying gutter continuation rows render as blank.

Copilot finished work on behalf of tig May 14, 2026 04:07
@tig
tig merged commit 94567d3 into develop May 14, 2026
8 checks passed
@tig
tig deleted the copilot/fix-mouse-caret-positioning branch May 14, 2026 13:23
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.

Mouse is not positioning caret properly with wordwrap

2 participants