Repository navigation
Description
Updated: April 24, 2020
The Custom Text Editor API has shipped with VS Code 1.44! Checkout the documentation and example extension to get started creating your custom text editors.
If you encounter any issues using CustomTextEditorProvider, please open a new issue.
This issue now tracks custom editors for binary files, which we aim to finalize for VS Code 1.46
Overview
The custom editor API aims to allow extensions to create fully customizable read/write editors that are used in place of VS Code's standard text editor for specific resources. These editors will be based on webviews. We will support editors for both binary and text resources
A XAML custom editor, for example, could show a WYSIWYG style editor for your .xaml files. Our end goal is to give extensions the most flexibility possible while keeping VS Code fast, lean, and consistent.
Non-goals
Many features that are potentially related to custom editors are out of scope of this current proposal, including:
- Specifying how resources are persisted and how resources are synchronized with webviews
- Specifying what an edit is
- Customization of VS Code's text editor using html / css
- Embedding of VS Code's text editor in webviews
- UI related to custom editors (beyond switching view types)
These all would fall under separate feature requests. Many also be a better fit for an external helper library instead of VS Code core
Tracking progress
This issue thread captures the evolution of the webview editor proposal. That means that many comments may now be out of date. Some of these have been minimized, others have not.
For the most up to date info, see:
Activity
mjbvz commentedon Jul 11, 2019
mjbvz commentedon Jul 11, 2019
jrieken commentedon Jul 11, 2019
TomMarius commentedon Jul 15, 2019
sijakret commentedon Jul 16, 2019
Is it possible i read in the docs for extension developers (about a year ago) that functionality like this was deliberately not supported for performance and stability reasons?
Not that i'm not hyped as well.. ;)
174 remaining items
hediet commentedon May 12, 2020
If you are interested, I wrote some thoughts down I had when I implemented the drawio editor for png files.
rdeline commentedon May 14, 2020
I'd like my custom text editor to have a different UI when a document is open normally versus in the source control diff view. (There are features that are unneeded in a diff.) However, given the arguments to
CustomTextEditorProvider.resolveCustomTextEditor, I don't see what logic I can write to tell that I'm in a diff view. In fact, for my use case, I'd prefer that Code use a regular text editor for diffs rather than creating my custom text editor. Maybe there's a way to specify that?mjbvz commentedon May 14, 2020
Rob DeLine (@rdeline) See #97683
zaydek commentedon May 21, 2020
Hi all. I’m looking for some advice to address several of my concerns implementing a custom text editor.
I’m working on a WYSIWYG markdown editor -- you can play with the technical prototype here: https://editor-v2-arch.netlify.app. I’ve been working on making the extension-version for VSCode, but I’m honestly pretty confused. I’ve followed the
abc(textarea) andcatScratchdemos for reference.What I’m most confused about is undo and cursor selection.
So when my editor is an extension, the undo stack actually appears to live outside of my editor, right? The reason this confuses me is because I already implemented all of the undo functionality myself, but now I need to let VSCode handle that for me? Am I simply not allowed to intercept undo/redo events myself and handle them? Is there a way I can change the relationship so my editor is in charge of handling undo/redo? Having this work the other way around is seriously confusing me.
I understand that I can emit edits on every event, and message-pass those edits to VSCode, but when a user hits undo, from what I can tell, the way my editor is made aware of this is by VSCode message-passing me the entire document as a string (naive implementation) or VSCode passing individual edits I can respond to. If I respond to individual edits, this seems fine (I would need to rearchitect some things to make this work) but this leads me to my second point: cursor selection.
When a user presses undo, they expect the cursor to revert to where it was. So assuming my editor responds to edits (as mentioned in the previous paragraph), does this mean I need to compute the cursor? Right now, my undo history stack tracks the cursor positions, so there’s no need for me to compute anything during an undo, redo event. But this seems like something else I would need to architect in order to get even the most basic editor behaviors working.
All things considered, making my editor VSCode-ready is proving to be way more difficult than I would have imagined. I hope I’ve got some things wrong here and there’s a much simpler way for me to port my editor.
jrieken commentedon May 26, 2020
@codex-zaydek You are on the wrong issue, this is about custom binary editors, please create a new one.
rchiodo commentedon May 29, 2020
Matt Bierner (@mjbvz) I was wondering how I would create an untitled editor with the new API? I believe we used to do this with a uri of
"untitled:Untitled-1.ipynb", but this gives an error now:Adding a '/' to the front of the file name seems to allow the creation of the file, but it's not treated as untitled (it's just treated as a real file then and closing doesn't ask to save as)
rchiodo commentedon May 29, 2020
Ah it seems there's already a discussion of this here:
#93441
mjbvz commentedon May 29, 2020
Rich Chiodo (@rchiodo) yes #93441 tracks a better solution. Until then, you should be able to create untitled files by using an
untitleduri that points to a specific file path:Move custom editor provider out of proposed to main api
mjbvz commentedon Jun 2, 2020
The binary custom editor API has been merged into
vscode.d.ts.If you were testing this proposed API previously, please make sure to update your code to call
registerCustomEditorProviderinstead ofregisterCustomEditorProvider2. Other than that, there should be no changes to the APIDemonOne commentedon Jun 3, 2020
Is there a way to change the title of a custom editor?
Right now my extension uses a webview witha custom title when editing a certain file, but I need the save/close features of the custom editor API.
mjbvz commentedon Jun 9, 2020
DemonOne No, custom editors currently always use the 'resource' as their title (they try to match what we do for normal text editors)
mjbvz commentedon Jun 9, 2020
The binary custom editor API will ship with VS Code 1.46 🎉 Thanks to everyone who helped test this API and provided feedback along the way
Follow up resources:
Going forward, please open any bugs/feature-requests/questions as new issues.