Repository navigation
fix #13945. support format on paste - #18476
Conversation
Johannes Rieken (jrieken)
left a comment
There was a problem hiding this comment.
Interesting approach. I was always thinking about a paste-listener and a setting but I actually like this. Left some nit comments, mostly around keybindings/menus
There was a problem hiding this comment.
Maybe 'Paste and Format'?
There was a problem hiding this comment.
We have context key which knows if for the current document there is someone that can format selections: ModeContextKeys.hasDocumentSelectionFormattingProvider (see FormatSelection as a sample). With that the menus will automatically update.
There was a problem hiding this comment.
Also register a keybinding and a menu item for this
b8631fb to
3f3ea06
Compare
|
Johannes Rieken (@jrieken) addressed your comments. Bind key chord |
|
On a second thought I am not so sure anymore if a separate action like 'Format and Paste' is the best solution. These are my concerns
|
|
Johannes Rieken (@jrieken) while implementing the command I have a feeling that ppl might prefer it as an option as well, I like |
|
Code looks good to me. Waiting for alexandrudima to review |
Alexandru Dima (alexdima)
left a comment
There was a problem hiding this comment.
Looks good overall, just a few details left.
| this.cursor.trigger(source, handlerId, payload); | ||
| const endPosition = this.cursor.getSelection().getStartPosition(); | ||
| if (source === 'keyboard') { | ||
| this.emit(editorCommon.EventType.DidPaste, { |
There was a problem hiding this comment.
I would prefer for the editor to always give out rich objects (i.e. Range and not IRange). It does so for all non-serializable events.
| * An event emitted when users paste text in the editor. | ||
| * @event | ||
| * @internal | ||
| */ |
There was a problem hiding this comment.
Here we say we give out a Range, but the implementation gives out an IRange. Please adjust the implementation.
| return; | ||
| } | ||
|
|
||
| var model = this.editor.getModel(); |
There was a problem hiding this comment.
nitpick: prefer let over var (same two lines below)
|
|
||
| // no support | ||
| var [support] = OnTypeFormattingEditProviderRegistry.ordered(model); | ||
| if (!support || !support.autoFormatTriggerCharacters) { |
There was a problem hiding this comment.
No need for the support to have autoFormatTriggerCharacters. Perhaps a copy-paste error?
There was a problem hiding this comment.
Now that I look at it, we should not read the OnTypeFormattingEditProvierRegistry, but the DocumentRangeFormatting bla bla Registry.
There was a problem hiding this comment.
Yup it's a stupid copy-paste error, I made changes to one place but forgot it here.
| } | ||
| const command = new EditOperationsCommand(edits, this.editor.getSelection()); | ||
| this.editor.executeCommand(this.getId(), command); | ||
| this.editor.focus(); |
There was a problem hiding this comment.
No need to focus here, since we are not moving the focus anywhere.
|
alexandrudima comments addressed. |
|
Brilliant! |
|
Peng Lyu (@rebornix) remember to create a test plan item for this |
|
Peng Lyu (@rebornix) alexandrudima i have done that |
Invoke format selection immediately after pasting event.