Skip to content

Change editor.action.focusNextCursor to reveal the primary cursor instead of all cursors - #182148

Merged
Alexandru Dima (alexdima) merged 3 commits into
microsoft:mainfrom
akbyrd:fix-cursor-controller-reveal-primary
Mar 20, 2024
Merged

Alexandru Dima (alexdima) merged 3 commits into
microsoft:mainfrom
akbyrd:fix-cursor-controller-reveal-primary

Conversation

@akbyrd

@akbyrd Adam Byrd (akbyrd) commented May 11, 2023 •

Copy link
Copy Markdown
Contributor

Closes #182147

Previously this command (and editor.action.focusPreviousCursor, introduced in #145909) called IViewModel.revealPrimaryCursor which in turn called CursorsController.revealPrimary. However, those names are deceptive. revealPrimary actually reveals all cursors. There are cases where revealing the primary cursor and not all cursors is desirable, such as commands dedicated to changing the primary cursor.

To support this I've renamed the existing "reveal primary" functions to "reveal all" and added a proper "reveal primary". I then updated editor.action.focusNextCursor and focusPreviousCursor to use the new "reveal primary" function.

All other commands that used "reveal primary" now use "reveal all" which is just a rename and they have the same behavior they had before.

Before:
Focus Next Cursor Fixed

After:
Focus Next Cursor Fixed

I audited the other uses of IViewModel.revealPrimaryCursor to determine if they want to reveal all cursors or the primary cursor.

These all remove secondary cursors, resulting in a single cursor so it doesn't matter what they use

  • BaseMoveToCommand
  • TopCommand
  • BottomCommand
  • CancelSelection
  • RemoveSecondaryCursors

These each make sense to "reveal all". No single cursor has a strong priority over others

  • CursorMoveImpl
  • CursorMoveBasedCommand
  • HomeCommand
  • EndCommand
  • LineStartCommand
  • LineEndCommand
  • ExpandLineSelectionAction

These probably want to reveal the most recently added cursor, but that concept doesn't currently exist.

  • WordCommand
  • LineCommand

LineCommand doesn't work properly with multiple cursors anyway, so it's currently a bit moot.

…into "reveal all" and "reveal primary" variants

- The original name was a lie. It wasn't revealing the primary cursor, it was revealing all cursors.
- Some things actually want to reveal the primary cursor specifically, such as editor.action.focusNextCursor. If the set of cursors do not all fit in the view and the primary cursor is not currently visible the primary cursor should be revealed.
- Other things want to reveal all cursors, such as cursorMove. However, there's likely room for improvement here as well: if the set of cursors do not all fit in the view and none of them are visible the closest cursor should probably be revealed.
- All existing locations have been updated to use "reveal all" which maintains the exact same behavior as before. Locations that want to use the primary variant will be updated in a separate commit.

@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) March 20, 2024 13:31
@alexdima Alexandru Dima (alexdima) added this to the March 2024 milestone Mar 20, 2024
@alexdima
Alexandru Dima (alexdima) merged commit 7f638be into microsoft:main Mar 20, 2024
@akbyrd
Adam Byrd (akbyrd) deleted the fix-cursor-controller-reveal-primary branch March 20, 2024 16:56
@microsoft Microsoft (microsoft) locked and limited conversation to collaborators Jun 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

editor.action.focusNextCursor doesn't reveal the primary cursor

3 participants