Skip to content

Normalize end of line cursor move operation - #296712

Merged
Alexandru Dima (alexdima) merged 3 commits into
microsoft:mainfrom
remcohaszing:line-wrap-move-right-affinity
Aug 24, 2026
Merged

Alexandru Dima (alexdima) merged 3 commits into
microsoft:mainfrom
remcohaszing:line-wrap-move-right-affinity

Conversation

@remcohaszing

Copy link
Copy Markdown
Contributor

When a line is wrapped, there are two view model positions that represent the same text model position. To illustrate, say we have the line text edit. We can represent it like this, where | represents the cursor position.

   0 1 2 3 4 5 6 7 8 9
1.  t e x t ·|e d i t

If we break it in the view model, it looks like this:

   0 1 2 3 4 5 6 7 8 9
1.  t e x t ·|
2. |e d i t

Both positions 1.5 and 2.0 represent the same text position. I did some testing on cursor behaviour, and found inconsistent behaviour across several editors:

  • Some editors split words if necessary, others only split on whitespace.
  • Some editors render the space on which the line is split, others don’t.
  • When pressing End from position 0.0, some editors move the cursor to 1.4, others to 1.5.

However, one specific thing is consistent across all editors I tried: If the cursor is at position 1.4, and you press the right arrow key, all editors move the cursor to position 2.0. I found this behaviour regardless of whether the line is split on whitespace or something else. Only Monaco moves the cursor to position 1.5.

This change makes Monaco behaviour consistent with other editors. I recorded two videos, one before, and one after, where I move the cursor to a line, and slowly keep pressing the right arrow key.

Before:

simplescreenrecorder-2026-02-21_11.08.11.webm

After:

simplescreenrecorder-2026-02-21_11.07.26.webm
Copilot AI balanced review requested due to automatic review settings August 21, 2026 07:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Normalizes right-cursor movement at wrapped-line boundaries to select the next visual line’s equivalent position.

Changes:

  • Applies right affinity after calculating the next cursor position.
Show a summary per file
File Description
src/vs/editor/common/cursor/cursorMoveOperations.ts Normalizes rightward cursor positions across wrap boundaries.

Review details

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Balanced
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@alexdima Alexandru Dima (alexdima) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you! ❤️

@alexdima
Alexandru Dima (alexdima) enabled auto-merge (squash) August 24, 2026 12:20
@alexdima
Alexandru Dima (alexdima) merged commit 8d4b385 into microsoft:main Aug 24, 2026
27 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.136.0 milestone Aug 24, 2026
@remcohaszing
Remco Haszing (remcohaszing) deleted the line-wrap-move-right-affinity branch August 24, 2026 13:10
Abdon Morales (abdonmorales) pushed a commit to abdonmorales/vscode-utcs that referenced this pull request Sep 27, 2026
* Normalize end of line cursor move operation

* Add wrapped line cursor move regression test

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Alexandru Dima <alex.dima@outlook.com>
Co-authored-by: Alex Dima <alexdima@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit 8d4b385)
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Oct 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

6 participants