File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4545 "command" : " imagePreview.zoomOut" ,
4646 "title" : " %command.zoomOut%" ,
4747 "category" : " Image Preview"
48+ },
49+ {
50+ "command" : " imagePreview.testing.makeEdit" ,
51+ "title" : " Make test edit" ,
52+ "category" : " Image Preview"
4853 }
4954 ],
5055 "menus" : {
5863 "command" : " imagePreview.zoomOut" ,
5964 "when" : " imagePreviewFocus" ,
6065 "group" : " 1_imagePreview"
66+ },
67+ {
68+ "command" : " imagePreview.testing.makeEdit" ,
69+ "when" : " imagePreviewTestMode" ,
70+ "group" : " 1_imagePreview"
6171 }
6272 ]
6373 }
Original file line number Diff line number Diff line change @@ -34,5 +34,20 @@ export function activate(context: vscode.ExtensionContext) {
3434 context . subscriptions . push ( vscode . commands . registerCommand ( 'imagePreview.zoomOut' , ( ) => {
3535 previewManager . activePreview ?. zoomOut ( ) ;
3636 } ) ) ;
37+
38+ context . subscriptions . push ( vscode . commands . registerCommand ( 'imagePreview.testing.makeEdit' , ( ) => {
39+ previewManager . activePreview ?. test_makeEdit ( ) ;
40+ } ) ) ;
41+
42+ context . subscriptions . push ( vscode . workspace . onDidChangeConfiguration ( e => {
43+ if ( e . affectsConfiguration ( 'imagePreview.customEditorTestMode' ) ) {
44+ updateTestMode ( ) ;
45+ }
46+ } ) ) ;
47+ updateTestMode ( ) ;
3748}
3849
50+ function updateTestMode ( ) {
51+ const isInTestMode = vscode . workspace . getConfiguration ( 'imagePreview' ) . get < boolean > ( 'customEditorTestMode' , false ) ;
52+ vscode . commands . executeCommand ( 'setContext' , 'imagePreviewTestMode' , isInTestMode ) ;
53+ }
Original file line number Diff line number Diff line change @@ -43,15 +43,8 @@ export class PreviewManager {
4343 }
4444 } ) ;
4545
46- const onEdit = new vscode . EventEmitter < { now : number } > ( ) ;
4746 return {
48- editingCapability : {
49- onEdit : onEdit . event ,
50- save : async ( ) => { } ,
51- hotExit : async ( ) => { } ,
52- applyEdits : async ( ) => { } ,
53- undoEdits : async ( edits ) => { console . log ( 'undo' , edits ) ; } ,
54- }
47+ editingCapability : preview
5548 } ;
5649 }
5750
@@ -73,7 +66,7 @@ const enum PreviewState {
7366 Active ,
7467}
7568
76- class Preview extends Disposable {
69+ class Preview extends Disposable implements vscode . WebviewEditorEditingCapability {
7770
7871 private readonly id : string = `${ Date . now ( ) } -${ Math . random ( ) . toString ( ) } ` ;
7972
@@ -246,6 +239,24 @@ class Preview extends Disposable {
246239 path : this . extensionRoot . path + path
247240 } ) ) ;
248241 }
242+
243+ //#region WebviewEditorCapabilities
244+ private readonly _onEdit = this . _register ( new vscode . EventEmitter < { now : number } > ( ) ) ;
245+ public readonly onEdit = this . _onEdit . event ;
246+
247+ async save ( ) { }
248+
249+ async hotExit ( ) { }
250+
251+ async applyEdits ( _edits : any [ ] ) { }
252+
253+ async undoEdits ( edits : any [ ] ) { console . log ( 'undo' , edits ) ; }
254+
255+ //#endregion
256+
257+ public test_makeEdit ( ) {
258+ this . _onEdit . fire ( { now : Date . now ( ) } ) ;
259+ }
249260}
250261
251262function escapeAttribute ( value : string | vscode . Uri ) : string {
You can’t perform that action at this time.
0 commit comments