Skip to content

Improve mirror cursor implementation with Synced Regions #88424

@octref

Description

@octref

Although some people like mirror cursor, it currently has issues. Many of these issues are existing behavior of multi-cursor. Some are hard to change, some can only be worked around in sophisticated ways, and some can only be fixed by code in vscode core.

UI wise, it has issues as well:

  • It's confusing which cursor in the main cursor
  • Content changes can happen outside viewport, and there's no indication
  • The multiple cursors aren't shown in scrollbar/minimap

And in my own experience, it doesn't play nicely with Vim extension.

In short, multi-cursor was the closest we could get to auto rename tag. We had to choose it because it's the only option for making 2 changes with 1 document edit. But it's not exactly the behavior people want (people want changes reflected in the mirrored region, not adding one more cursor).

Additionally, people has expressed interest in having mirror cursor for JSX: microsoft/TypeScript#51832
And we think it would be pretty cool, if this works for loop variables, function params, etc. For example:

for (let i|=0; i| < 10; i|++) {
  count += i|
}

To fix the issues, and to make this feature available to more languages, @alexdima, @jrieken and I think it's best to add a new editor concept, synced regions. It would work this way:

  • We introduce an API, OnTypeRenameProvider
  • When cursor moves in a doc, VS Code asks this provider for a list of ranges
  • These ranges are marked as in sync
  • Any content change (type, delete, paste) will cause all other synced regions to update in one edit
  • We can have a setting to switch between semi-automatic (press a shortcut to enter this mode) and full-automatic (like current mirror cursor).

Metadata

Metadata

Assignees

Labels

editor-synced-regionIssues related to synced region functionality in editorfeature-requestRequest for new features or functionalityon-testplan

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions