-
Notifications
You must be signed in to change notification settings - Fork 34.5k
Description
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.
- Pasting creates unwanted content at HTML closing tag Pasting after selecting html tag pastes twice #87067
- Duplicate line creates two lines Mirror cursor makes extra copy when duplicating row #87161
- Pasting create contents at two places [html] mirror cursor: pasting a full line will copy the full line twice #88072
- Multi cursor doesn't work nicely with mirror cursor [html] [rename on type] does not work properly with multicursor #88127
- When inserting space at
<h1|></h1>
, it creates 2 edits on undo stack [html] Mirror cursor devolves into multi-cursor when undoing (ctrl-z) #87732
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) andfull-automatic
(like current mirror cursor).