Skip to content

Commit 2c5f901

Browse files
authored
further polish of accept/discard gestures (microsoft#183417)
* further polish of accept/discard gestures return of the Accept btn, `escape` cancels, `cmd+enter` accepts, after cancel `cmd+z` restores the session fix toggle diff commands * fix unit test
1 parent d81d1e6 commit 2c5f901

File tree

6 files changed

+159
-61
lines changed

6 files changed

+159
-61
lines changed

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditor.contribution.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ registerSingleton(IInteractiveEditorSessionService, InteractiveEditorSessionServ
1818
registerEditorContribution(INTERACTIVE_EDITOR_ID, InteractiveEditorController, EditorContributionInstantiation.Lazy);
1919

2020
registerAction2(interactiveEditorActions.StartSessionAction);
21+
registerAction2(interactiveEditorActions.UnstashSessionAction);
2122
registerAction2(interactiveEditorActions.MakeRequestAction);
2223
registerAction2(interactiveEditorActions.StopRequestAction);
23-
registerAction2(interactiveEditorActions.DicardAction);
24+
registerAction2(interactiveEditorActions.DiscardAction);
2425
registerAction2(interactiveEditorActions.DiscardToClipboardAction);
2526
registerAction2(interactiveEditorActions.DiscardUndoToNewFileAction);
2627
registerAction2(interactiveEditorActions.CancelSessionAction);

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditorActions.ts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { EditorAction2 } from 'vs/editor/browser/editorExtensions';
1010
import { EmbeddedCodeEditorWidget, EmbeddedDiffEditorWidget } from 'vs/editor/browser/widget/embeddedCodeEditorWidget';
1111
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
1212
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, MENU_INTERACTIVE_EDITOR_WIDGET_DISCARD, MENU_INTERACTIVE_EDITOR_WIDGET_STATUS, CTX_INTERACTIVE_EDITOR_LAST_FEEDBACK, CTX_INTERACTIVE_EDITOR_SHOWING_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';
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_SHOWING_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, CTX_INTERACTIVE_EDITOR_HAS_STASHED_SESSION } from 'vs/workbench/contrib/interactiveEditor/common/interactiveEditor';
1414
import { localize } from 'vs/nls';
1515
import { IAction2Options, MenuRegistry } from 'vs/platform/actions/common/actions';
1616
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
@@ -66,6 +66,34 @@ export class StartSessionAction extends EditorAction2 {
6666
}
6767
}
6868

69+
export class UnstashSessionAction extends EditorAction2 {
70+
constructor() {
71+
super({
72+
id: 'interactiveEditor.unstash',
73+
title: { value: localize('unstash', 'Resume Last Dismissed Code Chat'), original: 'Resume Last Dismissed Code Chat' },
74+
category: AbstractInteractiveEditorAction.category,
75+
precondition: ContextKeyExpr.and(CTX_INTERACTIVE_EDITOR_HAS_STASHED_SESSION, EditorContextKeys.writable),
76+
keybinding: {
77+
weight: KeybindingWeight.WorkbenchContrib,
78+
primary: KeyMod.CtrlCmd | KeyCode.KeyZ,
79+
}
80+
});
81+
}
82+
83+
override runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor, ..._args: any[]) {
84+
const ctrl = InteractiveEditorController.get(editor);
85+
if (ctrl) {
86+
const session = ctrl.unstashLastSession();
87+
if (session) {
88+
ctrl.run({
89+
existingSession: session,
90+
isUnstashed: true
91+
});
92+
}
93+
}
94+
}
95+
}
96+
6997
abstract class AbstractInteractiveEditorAction extends EditorAction2 {
7098

7199
static readonly category = { value: localize('cat', 'Interactive Editor'), original: 'Interactive Editor' };
@@ -263,7 +291,7 @@ MenuRegistry.appendMenuItem(MENU_INTERACTIVE_EDITOR_WIDGET_STATUS, {
263291
});
264292

265293

266-
export class DicardAction extends AbstractInteractiveEditorAction {
294+
export class DiscardAction extends AbstractInteractiveEditorAction {
267295

268296
constructor() {
269297
super({
@@ -273,7 +301,7 @@ export class DicardAction extends AbstractInteractiveEditorAction {
273301
precondition: CTX_INTERACTIVE_EDITOR_VISIBLE,
274302
keybinding: {
275303
weight: KeybindingWeight.EditorContrib,
276-
primary: KeyMod.CtrlCmd + KeyCode.Escape
304+
primary: KeyCode.Escape
277305
},
278306
menu: {
279307
id: MENU_INTERACTIVE_EDITOR_WIDGET_DISCARD,
@@ -417,14 +445,9 @@ export class ApplyPreviewEdits extends AbstractInteractiveEditorAction {
417445
keybinding: [{
418446
weight: KeybindingWeight.EditorContrib + 10,
419447
primary: KeyMod.CtrlCmd | KeyCode.Enter,
420-
}, {
421-
weight: KeybindingWeight.EditorContrib + 10,
422-
primary: KeyCode.Escape,
423-
when: CTX_INTERACTIVE_EDITOR_EDIT_MODE.notEqualsTo(EditMode.Preview)
424448
}],
425449
menu: {
426450
id: MENU_INTERACTIVE_EDITOR_WIDGET_STATUS,
427-
when: CTX_INTERACTIVE_EDITOR_EDIT_MODE.isEqualTo(EditMode.Preview),
428451
group: '0_main',
429452
order: 0
430453
}

0 commit comments

Comments
 (0)