registerCustomEditorProvider
Supported from HBuilderX 2.9.2+
A complete custom editor example: how to extend a custom editor?
Introduction
Register a provider for custom editors for the viewType contributed by the customEditors extension point.
Parameter
Name | Type | Description |
---|---|---|
type | String | Unique identifier for the custom editor provider. This should match the viewType from the customEditors contribution point. |
provider | CustomEditorProvider | Provider that resolves custom editors. |
Example
hx.window.registerCustomEditorProvider("catEdit.catScratch", new CatCustomEditorProvider());
CustomDocument
Represents a custom document used by a CustomEditorProvider.
Attribute list
Attribute name | Type | Description |
---|---|---|
uri | String | The associated uri for this document. (File:///C:/abc/test.txt) |
CustomEditorProvider
Provider for editable custom editors that use a custom document model.
Attribute list
Attribute name | Type | Description |
---|---|---|
onDidChangeCustomDocument | HBuilderX built-in EventEmitter | Signal that an edit has occurred inside a custom editor. This event must be fired by your extension whenever an edit happens in a custom editor. |
Example
provider.onDidChangeCustomDocument.fire(new CustomDocumentEditEvent(document));
openCustomDocument
Create a new document for a given resource. openCustomDocument is called when the first time an editor for a given resource is opened. The opened document is then passed to resolveCustomEditor so that the editor can be shown to the user.
Parameter
Name | Type | Description |
---|---|---|
uri | String | Uri of the document to open. (File:///C:/abc/test.txt) |
Returns
Type | Description |
---|---|
Promise<CustomDocument> | The custom document. |
resolveCustomEditor
Resolve a custom editor for a given resource. This is called whenever the user opens a new editor for this CustomEditorProvider. The usage of WebViewPanel can also refer to some examples in View Extension.
Parameter
Name | Type | Description |
---|---|---|
document | CustomDocument | Document for the resource being resolved. |
webViewPanel | WebViewPanel | The webview panel used to display the editor UI for this resource. |
|
saveCustomDocument
Save a custom document. This method is invoked by the editor when the user saves a custom editor. This can happen when the user triggers save while the custom editor is active, by commands such as save all, or by auto save if enabled.
Parameter
Name | Type | Description |
---|---|---|
document | CustomDocument | Document to save. |
Returns
Type | Description |
---|---|
Promise<boolean> or boolean | Promise signaling that saving has completed. |
saveCustomDocumentAs
Save a custom document to a different location. This method is invoked by the editor when the user triggers ‘save as’ on a custom editor. The implementer must persist the custom editor to destination.
Parameter
Name | Type | Description |
---|---|---|
document | CustomDocument | Document to save. |
destination | String | Location to save to. (For example: file:///C:/abc/test.txt) |
Returns
Type | Description |
---|---|
Promise<boolean> or boolean | Promise signaling that saving has completed. |
CustomDocumentEditEvent
Event triggered by extensions to signal to the editor that an edit has occurred on an CustomDocument.