-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve mirror cursor implementation with Synced Regions #88424
Comments
Agreed. We'll make this an opt-in. |
I would add tow more problems:
I suggest to tweak mirror cursor by only activating it when the whole tag is selected (which is easily done with a double click), it's true that this way is a bit limiting in terms of per character editing, but in most cases re-typing the whole tag again is not so bad. |
Just an idea: Having a key to enter the mode always makes it less discoverable. Maybe one implementation could be:
For example:
|
I have tried out an editor contribution implementation with
I also cannot interleave The good things are this implementation would fix most of the complaints:
What I would need is an editor core concept/API, here's my sketches with @rebornix so far:
@alexdima Would love to hear your input here. |
Nice, this definitely needs built in editor support! As somebody working a lot with XML files, I'd really appreciate a solid mirroring of element tags and relatives. My use cases are:
<doc>
<!-- <element1> -->
<element2>
</element2>
<!-- </element1> -->
</doc>
While some of these currently can be done with various add-ons, they tend to break and the solutions are not solid. May I advice against needing to select the whole tag before this action? That would make editing very anti-fluid, especially in context of intellisense completions or correcting typos. Some other places, where this, or similar issues have arisen:
Of course, designing this API would require some philosophical evaluation about editor support vs. LSP support. My choice would be to keep this as simple as possible and leave the heavy lifting to an LSP, with a fallback for editor-only scenarios. Thank you for your consideration. |
Reopening to track API proposal and other polish items. |
Summary of the changes:
When you disable
When you enable This feature is only available for HTML now. But other language extensions can easily adopt it: /**
* The rename provider interface defines the contract between extensions and
* the live-rename feature.
*/
export interface OnTypeRenameProvider {
/**
* Provide a list of ranges that can be live renamed together.
*
* @param document The document in which the command was invoked.
* @param position The position at which the command was invoked.
* @param token A cancellation token.
* @return A list of ranges that can be live-renamed togehter. The ranges must have
* identical length and contain identical text content. The ranges cannot overlap.
*/
provideOnTypeRenameRanges(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<Range[]>;
}
namespace languages {
/**
* Register a rename provider that works on type.
*
* Multiple providers can be registered for a language. In that case providers are sorted
* by their [score](#languages.match) and the best-matching provider is used. Failure
* of the selected provider will cause a failure of the whole operation.
*
* @param selector A selector that defines the documents this provider is applicable to.
* @param provider An on type rename provider.
* @param stopPattern Stop on type renaming when input text matches the regular expression. Defaults to `^\s`.
* @return A [disposable](#Disposable) that unregisters this provider when being disposed.
*/
export function registerOnTypeRenameProvider(selector: DocumentSelector, provider: OnTypeRenameProvider, stopPattern?: RegExp): Disposable;
} Known issues:
Fixes:
|
Thanks! Really intrigued by these changes, will check them tomorrow. One question
It will exit mode if content starts with space or contains space anywhere? If I select |
The answer is - pasted as in in both places, so closing tag would also have class attribute :( @octref is it possible to
|
Thank you for looking into this! :-) This looks uncomfortable in so far, as it requires additional work, while typing. Ideally, when you type Renaming should happen from wherever you place the cursor in the element (start or end) and go on from there. If you paste text into the element name, it should just mirror this on the other side. P.S. I am aware, that text-completion is job of the LSP backend, I just mentioned it for sake of completeness, so I can describe. It would be really important, to have this feature work as seamlessly as possible, being part of the typing flow. P.P.S. What screen recorders do you guys use? I tried to find an easy to use, up to date and free one Windows, that would allow me to create screen records for Github, but I found none. |
It worked for me like this with
I've tried only few but found https://www.screentogif.com/ (+ pointed to downloaded https://ffmpeg.org/download.html ) as the best option for me. ffmpeg allows more export options from ScreenToGif + much better compression/quality |
@bmx I have been having good results with ScreenToGif |
Any content that matches
It doesn't match
No since we decided to make the feature language agnostic to editor, so other programming languages can implement this support.
People will complain about pasting Please open new issues with exact reproducible steps and expected behaviors. |
That's why my idea was to provide Return type of HTML/JSX will have In this 3 cases LS will provide this flag when ranges should have different behavior between ranges - open/closing tags: everything is pasted in first range (open tag), and only part before stop pasted into second range (closing tag). Other languages (or cases) - won't provide this flag - all places will have same treatment. That's rough idea, however I'd like see what drawbacks it has. |
I'm not sure how that would help with replacing Let's assume the |
Looks like I wasn't clear what I mean under "stopPattern is enforced" and that meaning of In case of [
{
range: new Range(1, 2, 1, 4)
},
{
range: new Range(1, 7, 1, 9),
enforceStopPattern: true
}
] when paste of
(yes, splitting is not optimal, but simples expample of how to take part before stop) Not sure yet sure what behavior is better if pasted value starts with Currently pasting |
@bmix In case you are looking for a mobile one as well, I've been using GIF Maker-Editor. It doesn't keep a logo or a button on top all the time and let you edit so you can cut off the start and end of the video/gif for not showing the parts you commanded it to start/end recording I just wish it could share with Giphy app to instantly upload it there |
@octref any feedback about behavior proposed in #88424 (comment) ? |
@IllusionMH I think
Without this feature, is that an edit you would do? |
API proposal is tracked in #94316. Will need to do that first before applying that to JSX / XML / etc. |
can be changed to any meaningful name e.g.
No I will not paste |
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.
<h1|></h1>
, it creates 2 edits on undo stack [html] Mirror cursor devolves into multi-cursor when undoing (ctrl-z) #87732UI wise, it has issues as well:
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:
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:
OnTypeRenameProvider
semi-automatic
(press a shortcut to enter this mode) andfull-automatic
(like current mirror cursor).The text was updated successfully, but these errors were encountered: