Adding setting to enable a test command for making a fake "edit" to an image preview

This will be use for testing custom editors
This commit is contained in:
Matt Bierner
2019-11-12 16:07:45 -08:00
parent 06a48362f3
commit 60f8583d95
3 changed files with 45 additions and 9 deletions

View File

@@ -45,6 +45,11 @@
"command": "imagePreview.zoomOut",
"title": "%command.zoomOut%",
"category": "Image Preview"
},
{
"command": "imagePreview.testing.makeEdit",
"title": "Make test edit",
"category": "Image Preview"
}
],
"menus": {
@@ -58,6 +63,11 @@
"command": "imagePreview.zoomOut",
"when": "imagePreviewFocus",
"group": "1_imagePreview"
},
{
"command": "imagePreview.testing.makeEdit",
"when": "imagePreviewTestMode",
"group": "1_imagePreview"
}
]
}

View File

@@ -34,5 +34,20 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand('imagePreview.zoomOut', () => {
previewManager.activePreview?.zoomOut();
}));
context.subscriptions.push(vscode.commands.registerCommand('imagePreview.testing.makeEdit', () => {
previewManager.activePreview?.test_makeEdit();
}));
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('imagePreview.customEditorTestMode')) {
updateTestMode();
}
}));
updateTestMode();
}
function updateTestMode() {
const isInTestMode = vscode.workspace.getConfiguration('imagePreview').get<boolean>('customEditorTestMode', false);
vscode.commands.executeCommand('setContext', 'imagePreviewTestMode', isInTestMode);
}

View File

@@ -43,15 +43,8 @@ export class PreviewManager {
}
});
const onEdit = new vscode.EventEmitter<{ now: number }>();
return {
editingCapability: {
onEdit: onEdit.event,
save: async () => { },
hotExit: async () => { },
applyEdits: async () => { },
undoEdits: async (edits) => { console.log('undo', edits); },
}
editingCapability: preview
};
}
@@ -73,7 +66,7 @@ const enum PreviewState {
Active,
}
class Preview extends Disposable {
class Preview extends Disposable implements vscode.WebviewEditorEditingCapability {
private readonly id: string = `${Date.now()}-${Math.random().toString()}`;
@@ -246,6 +239,24 @@ class Preview extends Disposable {
path: this.extensionRoot.path + path
}));
}
//#region WebviewEditorCapabilities
private readonly _onEdit = this._register(new vscode.EventEmitter<{ now: number }>());
public readonly onEdit = this._onEdit.event;
async save() { }
async hotExit() { }
async applyEdits(_edits: any[]) { }
async undoEdits(edits: any[]) { console.log('undo', edits); }
//#endregion
public test_makeEdit() {
this._onEdit.fire({ now: Date.now() });
}
}
function escapeAttribute(value: string | vscode.Uri): string {