mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
Working on sharing models for same custom editor
This commit is contained in:
@@ -273,8 +273,13 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
|
||||
|
||||
const model = await this._customEditorService.models.loadOrCreate(webviewInput.getResource(), webviewInput.viewType);
|
||||
|
||||
model.onUndo(edits => { this._proxy.$undoEdits(handle, edits); });
|
||||
model.onRedo(edits => { this._proxy.$redoEdits(handle, edits); });
|
||||
model.onUndo(edits => { this._proxy.$undoEdits(handle, edits.map(x => x.data)); });
|
||||
model.onApplyEdit(edits => {
|
||||
const editsToApply = edits.filter(x => x.source !== webviewInput).map(x => x.data);
|
||||
if (editsToApply.length) {
|
||||
this._proxy.$applyEdits(handle, editsToApply);
|
||||
}
|
||||
});
|
||||
model.onWillSave(e => { e.waitUntil(this._proxy.$onSave(handle)); });
|
||||
model.onWillSaveAs(e => { e.waitUntil(this._proxy.$onSaveAs(handle, e.resource.toJSON(), e.targetResource.toJSON())); });
|
||||
|
||||
@@ -309,7 +314,7 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
|
||||
this._editorProviders.delete(viewType);
|
||||
}
|
||||
|
||||
public $onEdit(handle: extHostProtocol.WebviewPanelHandle, editData: string): void {
|
||||
public $onEdit(handle: extHostProtocol.WebviewPanelHandle, editData: any): void {
|
||||
const webview = this.getWebviewInput(handle);
|
||||
if (!(webview instanceof CustomFileEditorInput)) {
|
||||
throw new Error('Webview is not a webview editor');
|
||||
@@ -320,7 +325,7 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
|
||||
throw new Error('Could not find model for webview editor');
|
||||
}
|
||||
|
||||
model.makeEdit(editData);
|
||||
model.makeEdit({ source: webview, data: editData });
|
||||
}
|
||||
|
||||
private hookupWebviewEventDelegate(handle: extHostProtocol.WebviewPanelHandle, input: WebviewInput) {
|
||||
|
||||
@@ -574,7 +574,7 @@ export interface MainThreadWebviewsShape extends IDisposable {
|
||||
$registerEditorProvider(extension: WebviewExtensionDescription, viewType: string, options: modes.IWebviewPanelOptions): void;
|
||||
$unregisterEditorProvider(viewType: string): void;
|
||||
|
||||
$onEdit(handle: WebviewPanelHandle, editJson: string): void;
|
||||
$onEdit(handle: WebviewPanelHandle, editJson: any): void;
|
||||
}
|
||||
|
||||
export interface WebviewPanelViewStateData {
|
||||
@@ -595,7 +595,7 @@ export interface ExtHostWebviewsShape {
|
||||
$resolveWebviewEditor(resource: UriComponents, newWebviewHandle: WebviewPanelHandle, viewType: string, title: string, position: EditorViewColumn, options: modes.IWebviewOptions & modes.IWebviewPanelOptions): Promise<void>;
|
||||
|
||||
$undoEdits(handle: WebviewPanelHandle, edits: readonly any[]): void;
|
||||
$redoEdits(handle: WebviewPanelHandle, edits: readonly any[]): void;
|
||||
$applyEdits(handle: WebviewPanelHandle, edits: readonly any[]): void;
|
||||
|
||||
$onSave(handle: WebviewPanelHandle): Promise<void>;
|
||||
$onSaveAs(handle: WebviewPanelHandle, resource: UriComponents, targetResource: UriComponents): Promise<void>;
|
||||
|
||||
@@ -457,7 +457,7 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
|
||||
panel?._undoEdits(edits);
|
||||
}
|
||||
|
||||
$redoEdits(handle: WebviewPanelHandle, edits: string[]): void {
|
||||
$applyEdits(handle: WebviewPanelHandle, edits: string[]): void {
|
||||
const panel = this.getWebviewPanel(handle);
|
||||
panel?._redoEdits(edits);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user