-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
Prototyping custom editors #77789
Prototyping custom editors #77789
Conversation
src/vs/workbench/browser/editor.ts
Outdated
@@ -8,13 +8,16 @@ import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; | |||
import { Registry } from 'vs/platform/registry/common/platform'; | |||
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor'; | |||
import { IConstructorSignature0, IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; | |||
import { URI } from 'vs/base/common/uri'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{}); | ||
|
||
if (pick) { | ||
bigInput.setPreferredCustomEditor(pick.id!); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe inputs are lightweight and short lived and therefore this has no effect?
@jrieken @bpasero Ran into some problems with the current design when you reload the workbench. The main issue is that the editor contributions from extension have not been processed when we first restore the active editor, so we always end up falling back to the normal text editor instead. Just a quick overview of the current design:
This model is nice because it allows us to treat custom editors just like our built-in text and binary editors. However the current design requires that we create the custom Here are some sketches of how I think we could get around this: Have a single custom editor class:
Eagerly activate a placeholder custom editor while restoring state
|
Yeah, I believe having one custom editor implementation is enough. It's role should then be to get extensions ready. I am not sure about the changes in |
Yeah may seems to be what we'll have to do. The reason I tried to avoid creating a new editor input type is that i wasn't sure how to tell VS Code to instantiate our custom input type instead of |
From an API point of view we should also explore a more loose approach, e.g instead of the relying on the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mjbvz I would suggest to go down the path of introducing a new editor input for this work. That saves you the trouble of restoring state between restarts and would not require any changes to the FileEditorInput
at all, which imho is not the right place to make these changes to begin with.
We already have a mechanism in place that allows to prevent the default action of opening an editor to replace with another editor to open by listening to onWillOpenEditor
and calling the prevent
method by returning a custom editor. I suggest to experiment with that approach and see how far you get. We initially added this event for the scenario of a user clicking on settings.json
in the .vscode
folder and then opening the settings UI editor instead of the file (we no longer seem to do that though @sandy081 @roblourens fyi). But the event is still there and can be used. We can enrich it with more stuff as needed for this feature.
Another feedback I have is: we should not tie this to webview editors alone. The binary editor extension for example is NOT using a webview editor as far as I can tell, but a normal text editor with a document that can be changed.
Hi @mjbvz! That's a really nice idea. Like the progress you made so far. Do you have plans to extend the WebviewEditor interface to implement more than the WebviewPanel interface? I'm asking that because from the GIF you posted, I can't tell if there's editing capabilities on these "custom editors". For example, the From your TODO list, I'm assuming it is possible to edit the contents on a WebviewEditor, but then, if you edit the content of a file using a custom editor, is there a way to "override" the save command? Because I assume you'll need to convert whatever you have on your custom editor to text/bytes, right? Anyway, sorry to appear out of nowhere, I'm just really interested on this feature :) Thanks! |
1c1904c
to
0fe7f6a
Compare
@tiagobento See #77131 |
8052756
to
aeb38de
Compare
90775ff
to
7ab1882
Compare
cd90d0b
to
a47af87
Compare
For #77131 Adds a prototype of custom editors contributed by extensions. This change does the following: - Introduces a new contribution point for the declarative parts of a custom editor - Adds API for registering a webview editor provider. This lets VS Code decided when to create a webview editor - Adds an `openWith` command that lets you select which editor to use to open a resource from the file explorer - Adds a setting that lets you say that you always want to use a custom editor for a given file extension - Hooks up auto opening of a custom editor when opening a file from quick open or explorer - Adds a new extension that contributes a custom image preview for png and jpg files Still needs a lot of UX work and testing. We are also going to explore a more generic "open handler" based approach for supporting custom editors Revert
…om resoruces for custom editors
Changes `enableByDefault` boolean to a `discretion` enum. This should give more flexibility if we want other options (such as forcing a given custom editor to always be used even if there are other default ones)
5ee044b
to
d09659b
Compare
For #77131
Adds a prototype of custom editors contributed by extensions. This change does the following:
openWith
command that lets you select which editor to use to open a resource from the file explorerStill needs a lot of UX work and testing. We are also going to explore a more generic "open handler" based approach for supporting custom editors