@@ -10,7 +10,7 @@ import { EditorAction2 } from 'vs/editor/browser/editorExtensions';
10
10
import { EmbeddedCodeEditorWidget , EmbeddedDiffEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget' ;
11
11
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys' ;
12
12
import { InteractiveEditorController , InteractiveEditorRunOptions } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorController' ;
13
- import { CTX_INTERACTIVE_EDITOR_FOCUSED , CTX_INTERACTIVE_EDITOR_HAS_ACTIVE_REQUEST , CTX_INTERACTIVE_EDITOR_HAS_PROVIDER , CTX_INTERACTIVE_EDITOR_INNER_CURSOR_FIRST , CTX_INTERACTIVE_EDITOR_INNER_CURSOR_LAST , CTX_INTERACTIVE_EDITOR_EMPTY , CTX_INTERACTIVE_EDITOR_OUTER_CURSOR_POSITION , CTX_INTERACTIVE_EDITOR_VISIBLE , MENU_INTERACTIVE_EDITOR_WIDGET , CTX_INTERACTIVE_EDITOR_LAST_EDIT_TYPE , MENU_INTERACTIVE_EDITOR_WIDGET_UNDO , MENU_INTERACTIVE_EDITOR_WIDGET_STATUS , CTX_INTERACTIVE_EDITOR_LAST_FEEDBACK , CTX_INTERACTIVE_EDITOR_INLNE_DIFF , CTX_INTERACTIVE_EDITOR_EDIT_MODE , EditMode , CTX_INTERACTIVE_EDITOR_LAST_RESPONSE_TYPE , MENU_INTERACTIVE_EDITOR_WIDGET_MARKDOWN_MESSAGE , CTX_INTERACTIVE_EDITOR_MESSAGE_CROP_STATE , CTX_INTERACTIVE_EDITOR_DOCUMENT_CHANGED } from 'vs/workbench/contrib/interactiveEditor/common/interactiveEditor' ;
13
+ import { CTX_INTERACTIVE_EDITOR_FOCUSED , CTX_INTERACTIVE_EDITOR_HAS_ACTIVE_REQUEST , CTX_INTERACTIVE_EDITOR_HAS_PROVIDER , CTX_INTERACTIVE_EDITOR_INNER_CURSOR_FIRST , CTX_INTERACTIVE_EDITOR_INNER_CURSOR_LAST , CTX_INTERACTIVE_EDITOR_EMPTY , CTX_INTERACTIVE_EDITOR_OUTER_CURSOR_POSITION , CTX_INTERACTIVE_EDITOR_VISIBLE , MENU_INTERACTIVE_EDITOR_WIDGET , MENU_INTERACTIVE_EDITOR_WIDGET_DISCARD , MENU_INTERACTIVE_EDITOR_WIDGET_STATUS , CTX_INTERACTIVE_EDITOR_LAST_FEEDBACK , CTX_INTERACTIVE_EDITOR_INLNE_DIFF , CTX_INTERACTIVE_EDITOR_EDIT_MODE , EditMode , CTX_INTERACTIVE_EDITOR_LAST_RESPONSE_TYPE , MENU_INTERACTIVE_EDITOR_WIDGET_MARKDOWN_MESSAGE , CTX_INTERACTIVE_EDITOR_MESSAGE_CROP_STATE , CTX_INTERACTIVE_EDITOR_DOCUMENT_CHANGED , CTX_INTERACTIVE_EDITOR_DID_EDIT } from 'vs/workbench/contrib/interactiveEditor/common/interactiveEditor' ;
14
14
import { localize } from 'vs/nls' ;
15
15
import { IAction2Options } from 'vs/platform/actions/common/actions' ;
16
16
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService' ;
@@ -20,7 +20,6 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis
20
20
import { IQuickInputService , IQuickPickItem } from 'vs/platform/quickinput/common/quickInput' ;
21
21
import { IEditorService , SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService' ;
22
22
import { IUntitledTextResourceEditorInput } from 'vs/workbench/common/editor' ;
23
- import { ILogService } from 'vs/platform/log/common/log' ;
24
23
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService' ;
25
24
import { Range } from 'vs/editor/common/core/range' ;
26
25
import { fromNow } from 'vs/base/common/date' ;
@@ -251,86 +250,79 @@ export class NextFromHistory extends AbstractInteractiveEditorAction {
251
250
}
252
251
}
253
252
254
-
255
- export class UndoToClipboard extends AbstractInteractiveEditorAction {
253
+ export class DicardAction extends AbstractInteractiveEditorAction {
256
254
257
255
constructor ( ) {
258
256
super ( {
259
- id : 'interactiveEditor.undoToClipboard ' ,
260
- title : localize ( 'undo.clipboard ' , 'Undo to Clipboard ' ) ,
261
- precondition : ContextKeyExpr . and ( CTX_INTERACTIVE_EDITOR_VISIBLE , CTX_INTERACTIVE_EDITOR_LAST_EDIT_TYPE . isEqualTo ( 'simple' ) ) ,
262
- keybinding : {
263
- weight : KeybindingWeight . EditorContrib + 10 ,
264
- primary : KeyMod . CtrlCmd | KeyMod . Shift | KeyCode . KeyZ ,
265
- mac : { primary : KeyMod . CtrlCmd | KeyMod . Alt | KeyCode . KeyZ } ,
266
- } ,
257
+ id : 'interactiveEditor.discard ' ,
258
+ title : localize ( 'discard ' , 'Discard ' ) ,
259
+ icon : Codicon . discard ,
260
+ precondition : CTX_INTERACTIVE_EDITOR_VISIBLE ,
261
+ // keybinding: {
262
+ // weight: KeybindingWeight.EditorContrib - 1 ,
263
+ // primary: KeyCode.Escape
264
+ // },
267
265
menu : {
268
- when : CTX_INTERACTIVE_EDITOR_LAST_EDIT_TYPE . isEqualTo ( 'simple' ) ,
269
- id : MENU_INTERACTIVE_EDITOR_WIDGET_UNDO ,
270
- group : '1_undo' ,
271
- order : 1
266
+ id : MENU_INTERACTIVE_EDITOR_WIDGET_DISCARD ,
267
+ order : 0
272
268
}
273
269
} ) ;
274
270
}
275
271
276
- override runInteractiveEditorCommand ( accessor : ServicesAccessor , ctrl : InteractiveEditorController ) : void {
277
- const clipboardService = accessor . get ( IClipboardService ) ;
278
- const lastText = ctrl . undoLast ( ) ;
279
- if ( lastText !== undefined ) {
280
- clipboardService . writeText ( lastText ) ;
281
- }
272
+ async runInteractiveEditorCommand ( _accessor : ServicesAccessor , ctrl : InteractiveEditorController , _editor : ICodeEditor , ..._args : any [ ] ) : Promise < void > {
273
+ await ctrl . cancelSession ( ) ;
282
274
}
283
275
}
284
276
285
- export class UndoToNewFile extends AbstractInteractiveEditorAction {
277
+ export class DiscardToClipboardAction extends AbstractInteractiveEditorAction {
286
278
287
279
constructor ( ) {
288
280
super ( {
289
- id : 'interactiveEditor.undoToFile' ,
290
- title : localize ( 'undo.newfile' , 'Undo to New File' ) ,
291
- precondition : ContextKeyExpr . and ( CTX_INTERACTIVE_EDITOR_VISIBLE , CTX_INTERACTIVE_EDITOR_LAST_EDIT_TYPE . isEqualTo ( 'simple' ) ) ,
281
+ id : 'interactiveEditor.discardToClipboard' ,
282
+ title : localize ( 'undo.clipboard' , 'Discard to Clipboard' ) ,
283
+ precondition : ContextKeyExpr . and ( CTX_INTERACTIVE_EDITOR_VISIBLE , CTX_INTERACTIVE_EDITOR_DID_EDIT ) ,
284
+ // keybinding: {
285
+ // weight: KeybindingWeight.EditorContrib + 10,
286
+ // primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KeyZ,
287
+ // mac: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KeyZ },
288
+ // },
292
289
menu : {
293
- when : CTX_INTERACTIVE_EDITOR_LAST_EDIT_TYPE . isEqualTo ( 'simple' ) ,
294
- id : MENU_INTERACTIVE_EDITOR_WIDGET_UNDO ,
295
- group : '1_undo' ,
296
- order : 2
290
+ id : MENU_INTERACTIVE_EDITOR_WIDGET_DISCARD ,
291
+ order : 1
297
292
}
298
293
} ) ;
299
294
}
300
295
301
- override runInteractiveEditorCommand ( accessor : ServicesAccessor , ctrl : InteractiveEditorController , editor : ICodeEditor , ..._args : any [ ] ) : void {
302
- const editorService = accessor . get ( IEditorService ) ;
303
- const lastText = ctrl . undoLast ( ) ;
304
- if ( lastText !== undefined ) {
305
- const input : IUntitledTextResourceEditorInput = { forceUntitled : true , resource : undefined , contents : lastText , languageId : editor . getModel ( ) ?. getLanguageId ( ) } ;
306
- editorService . openEditor ( input , SIDE_GROUP ) ;
296
+ override async runInteractiveEditorCommand ( accessor : ServicesAccessor , ctrl : InteractiveEditorController ) : Promise < void > {
297
+ const clipboardService = accessor . get ( IClipboardService ) ;
298
+ const changedText = await ctrl . cancelSession ( ) ;
299
+ if ( changedText !== undefined ) {
300
+ clipboardService . writeText ( changedText ) ;
307
301
}
308
302
}
309
303
}
310
304
311
- export class UndoCommand extends AbstractInteractiveEditorAction {
305
+ export class DiscardUndoToNewFileAction extends AbstractInteractiveEditorAction {
312
306
313
307
constructor ( ) {
314
308
super ( {
315
- id : 'interactiveEditor.undo' ,
316
- title : localize ( 'undo' , 'Undo' ) ,
317
- icon : Codicon . commentDiscussion ,
318
- precondition : ContextKeyExpr . and ( CTX_INTERACTIVE_EDITOR_VISIBLE , CTX_INTERACTIVE_EDITOR_LAST_EDIT_TYPE . isEqualTo ( 'simple' ) ) ,
319
- // keybinding: {
320
- // weight: KeybindingWeight.EditorContrib + 10,
321
- // primary: KeyMod.CtrlCmd | KeyCode.KeyZ,
322
- // },
309
+ id : 'interactiveEditor.discardToFile' ,
310
+ title : localize ( 'undo.newfile' , 'Discard to New File' ) ,
311
+ precondition : ContextKeyExpr . and ( CTX_INTERACTIVE_EDITOR_VISIBLE , CTX_INTERACTIVE_EDITOR_DID_EDIT ) ,
323
312
menu : {
324
- when : CTX_INTERACTIVE_EDITOR_LAST_EDIT_TYPE . isEqualTo ( 'simple' ) ,
325
- id : MENU_INTERACTIVE_EDITOR_WIDGET_UNDO ,
326
- group : '1_undo' ,
327
- order : 3
313
+ id : MENU_INTERACTIVE_EDITOR_WIDGET_DISCARD ,
314
+ order : 2
328
315
}
329
316
} ) ;
330
317
}
331
318
332
- override runInteractiveEditorCommand ( _accessor : ServicesAccessor , ctrl : InteractiveEditorController ) : void {
333
- ctrl . undoLast ( ) ;
319
+ override async runInteractiveEditorCommand ( accessor : ServicesAccessor , ctrl : InteractiveEditorController , editor : ICodeEditor , ..._args : any [ ] ) : Promise < void > {
320
+ const editorService = accessor . get ( IEditorService ) ;
321
+ const changedText = await ctrl . cancelSession ( ) ;
322
+ if ( changedText !== undefined ) {
323
+ const input : IUntitledTextResourceEditorInput = { forceUntitled : true , resource : undefined , contents : changedText , languageId : editor . getModel ( ) ?. getLanguageId ( ) } ;
324
+ editorService . openEditor ( input , SIDE_GROUP ) ;
325
+ }
334
326
}
335
327
}
336
328
@@ -409,30 +401,25 @@ export class ApplyPreviewEdits extends AbstractInteractiveEditorAction {
409
401
title : localize ( 'applyEdits' , 'Apply Changes' ) ,
410
402
icon : Codicon . check ,
411
403
precondition : ContextKeyExpr . and ( CTX_INTERACTIVE_EDITOR_VISIBLE , ContextKeyExpr . or ( CTX_INTERACTIVE_EDITOR_DOCUMENT_CHANGED . toNegated ( ) , CTX_INTERACTIVE_EDITOR_EDIT_MODE . notEqualsTo ( EditMode . Preview ) ) ) ,
412
- keybinding : {
404
+ keybinding : [ {
413
405
weight : KeybindingWeight . EditorContrib + 10 ,
414
- primary : KeyMod . CtrlCmd | KeyCode . Enter
415
- } ,
406
+ primary : KeyMod . CtrlCmd | KeyCode . Enter ,
407
+ } , {
408
+ weight : KeybindingWeight . EditorContrib + 10 ,
409
+ primary : KeyCode . Escape ,
410
+ when : CTX_INTERACTIVE_EDITOR_EDIT_MODE . notEqualsTo ( EditMode . Preview )
411
+ } ] ,
416
412
menu : {
417
413
id : MENU_INTERACTIVE_EDITOR_WIDGET_STATUS ,
414
+ when : CTX_INTERACTIVE_EDITOR_EDIT_MODE . isEqualTo ( EditMode . Preview ) ,
418
415
group : '0_main' ,
419
416
order : 0
420
417
}
421
418
} ) ;
422
419
}
423
420
424
- override async runInteractiveEditorCommand ( accessor : ServicesAccessor , ctrl : InteractiveEditorController ) : Promise < void > {
425
- const logService = accessor . get ( ILogService ) ;
426
- const editorService = accessor . get ( IEditorService ) ;
427
- const edit = await ctrl . applyChanges ( ) ;
428
- if ( ! edit ) {
429
- logService . warn ( 'FAILED to apply changes, no edit response' ) ;
430
- return ;
431
- }
432
- if ( edit . singleCreateFileEdit ) {
433
- editorService . openEditor ( { resource : edit . singleCreateFileEdit . uri } , SIDE_GROUP ) ;
434
- }
435
-
421
+ override async runInteractiveEditorCommand ( _accessor : ServicesAccessor , ctrl : InteractiveEditorController ) : Promise < void > {
422
+ await ctrl . applyChanges ( ) ;
436
423
}
437
424
}
438
425
@@ -441,15 +428,16 @@ export class CancelSessionAction extends AbstractInteractiveEditorAction {
441
428
constructor ( ) {
442
429
super ( {
443
430
id : 'interactiveEditor.cancel' ,
444
- title : localize ( 'discard ' , 'Discard Changes ' ) ,
431
+ title : localize ( 'cancel ' , 'Cancel ' ) ,
445
432
icon : Codicon . clearAll ,
446
- precondition : CTX_INTERACTIVE_EDITOR_VISIBLE ,
433
+ precondition : ContextKeyExpr . and ( CTX_INTERACTIVE_EDITOR_VISIBLE , CTX_INTERACTIVE_EDITOR_EDIT_MODE . isEqualTo ( EditMode . Preview ) ) ,
447
434
keybinding : {
448
435
weight : KeybindingWeight . EditorContrib - 1 ,
449
436
primary : KeyCode . Escape
450
437
} ,
451
438
menu : {
452
439
id : MENU_INTERACTIVE_EDITOR_WIDGET_STATUS ,
440
+ when : CTX_INTERACTIVE_EDITOR_EDIT_MODE . isEqualTo ( EditMode . Preview ) ,
453
441
group : '0_main' ,
454
442
order : 1
455
443
}
@@ -468,7 +456,8 @@ export class CopyRecordings extends AbstractInteractiveEditorAction {
468
456
id : 'interactiveEditor.copyRecordings' ,
469
457
f1 : true ,
470
458
title : {
471
- value : localize ( 'copyRecordings' , '(Developer) Write Exchange to Clipboard' ) , original : '(Developer) Write Exchange to Clipboard'
459
+ value : localize ( 'copyRecordings' , '(Developer) Write Exchange to Clipboard' ) ,
460
+ original : '(Developer) Write Exchange to Clipboard'
472
461
}
473
462
} ) ;
474
463
}
0 commit comments