Skip to content

Comments

Normalize end of line cursor move operation#296712

Open
remcohaszing wants to merge 1 commit intomicrosoft:mainfrom
remcohaszing:line-wrap-move-right-affinity
Open

Normalize end of line cursor move operation#296712
remcohaszing wants to merge 1 commit intomicrosoft:mainfrom
remcohaszing:line-wrap-move-right-affinity

Conversation

@remcohaszing
Copy link
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants