Skip to content

Commit

Permalink
refactor: unify Cancel button for chat views (#230743)
Browse files Browse the repository at this point in the history
  • Loading branch information
joyceerhl authored Oct 7, 2024
1 parent 5365a73 commit 6f3888b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ContextKeyExpr } from '../../../../../platform/contextkey/common/contex
import { KeybindingWeight } from '../../../../../platform/keybinding/common/keybindingsRegistry.js';
import { ChatAgentLocation, IChatAgentService } from '../../common/chatAgents.js';
import { CONTEXT_CHAT_INPUT_HAS_AGENT, CONTEXT_CHAT_INPUT_HAS_TEXT, CONTEXT_CHAT_LOCATION, CONTEXT_CHAT_REQUEST_IN_PROGRESS, CONTEXT_IN_CHAT_INPUT, CONTEXT_LANGUAGE_MODELS_ARE_USER_SELECTABLE, CONTEXT_PARTICIPANT_SUPPORTS_MODEL_PICKER } from '../../common/chatContextKeys.js';
import { applyingChatEditsContextKey } from '../../common/chatEditingService.js';
import { applyingChatEditsContextKey, IChatEditingService } from '../../common/chatEditingService.js';
import { chatAgentLeader, extractAgentAndCommand } from '../../common/chatParserTypes.js';
import { IChatService } from '../../common/chatService.js';
import { IChatWidget, IChatWidgetService } from '../chat.js';
Expand Down Expand Up @@ -167,7 +167,7 @@ export class CancelAction extends Action2 {
icon: Codicon.stopCircle,
menu: {
id: MenuId.ChatExecute,
when: ContextKeyExpr.and(CONTEXT_CHAT_REQUEST_IN_PROGRESS, CONTEXT_CHAT_LOCATION.notEqualsTo(ChatAgentLocation.EditingSession)),
when: ContextKeyExpr.or(CONTEXT_CHAT_REQUEST_IN_PROGRESS, ContextKeyExpr.and(CONTEXT_CHAT_LOCATION.isEqualTo(ChatAgentLocation.EditingSession), applyingChatEditsContextKey)),
order: 4,
group: 'navigation',
},
Expand All @@ -192,6 +192,12 @@ export class CancelAction extends Action2 {
if (widget.viewModel) {
chatService.cancelCurrentRequestForSession(widget.viewModel.sessionId);
}

const chatEditingService = accessor.get(IChatEditingService);
const currentEditingSession = chatEditingService.currentEditingSession;
if (currentEditingSession && currentEditingSession?.chatSessionId === widget.viewModel?.sessionId) {
chatEditingService.currentAutoApplyOperation?.cancel();
}
}
}

Expand Down
50 changes: 1 addition & 49 deletions src/vs/workbench/contrib/chat/browser/chatEditingActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@
*--------------------------------------------------------------------------------------------*/

import { Codicon } from '../../../../base/common/codicons.js';
import { KeyCode, KeyMod } from '../../../../base/common/keyCodes.js';
import { ResourceSet } from '../../../../base/common/map.js';
import { URI } from '../../../../base/common/uri.js';
import { ServicesAccessor } from '../../../../editor/browser/editorExtensions.js';
import { localize, localize2 } from '../../../../nls.js';
import { Action2, MenuId, registerAction2 } from '../../../../platform/actions/common/actions.js';
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
import { EditorActivation } from '../../../../platform/editor/common/editor.js';
import { KeybindingWeight } from '../../../../platform/keybinding/common/keybindingsRegistry.js';
import { IListService } from '../../../../platform/list/browser/listService.js';
import { GroupsOrder, IEditorGroupsService } from '../../../services/editor/common/editorGroupsService.js';
import { IEditorService } from '../../../services/editor/common/editorService.js';
import { ChatAgentLocation } from '../common/chatAgents.js';
import { CONTEXT_CHAT_LOCATION, CONTEXT_CHAT_REQUEST_IN_PROGRESS } from '../common/chatContextKeys.js';
import { applyingChatEditsContextKey, CHAT_EDITING_MULTI_DIFF_SOURCE_RESOLVER_SCHEME, chatEditingResourceContextKey, chatEditingWidgetFileStateContextKey, decidedChatEditingResourceContextKey, IChatEditingService, IChatEditingSession, inChatEditingSessionContextKey, WorkingSetEntryState } from '../common/chatEditingService.js';
import { IChatService } from '../common/chatService.js';
import { CHAT_EDITING_MULTI_DIFF_SOURCE_RESOLVER_SCHEME, chatEditingResourceContextKey, chatEditingWidgetFileStateContextKey, decidedChatEditingResourceContextKey, IChatEditingService, IChatEditingSession, inChatEditingSessionContextKey, WorkingSetEntryState } from '../common/chatEditingService.js';
import { CHAT_CATEGORY } from './actions/chatActions.js';
import { IChatExecuteActionContext } from './actions/chatExecuteActions.js';
import { IChatWidget, IChatWidgetService } from './chat.js';

abstract class WorkingSetAction extends Action2 {
Expand Down Expand Up @@ -279,45 +273,3 @@ registerAction2(class AddFilesToWorkingSetAction extends Action2 {
}
}
});

registerAction2(class CancelAction extends Action2 {
static readonly ID = 'workbench.action.chat.editing.cancel';
constructor() {
super({
id: CancelAction.ID,
title: localize2('workbench.action.chat.editing.cancel.label', "Cancel"),
f1: false,
category: CHAT_CATEGORY,
icon: Codicon.stopCircle,
menu: {
id: MenuId.ChatExecute,
when: ContextKeyExpr.and(CONTEXT_CHAT_LOCATION.isEqualTo(ChatAgentLocation.EditingSession), ContextKeyExpr.or(CONTEXT_CHAT_REQUEST_IN_PROGRESS, applyingChatEditsContextKey)),
order: 4,
group: 'navigation',
},
keybinding: {
weight: KeybindingWeight.WorkbenchContrib,
primary: KeyMod.CtrlCmd | KeyCode.Escape,
win: { primary: KeyMod.Alt | KeyCode.Backspace },
}
});
}

run(accessor: ServicesAccessor, ...args: any[]) {
const context: IChatExecuteActionContext | undefined = args[0];

const widgetService = accessor.get(IChatWidgetService);
const widget = context?.widget ?? widgetService.lastFocusedWidget;
if (!widget) {
return;
}

const chatService = accessor.get(IChatService);
if (widget.viewModel) {
chatService.cancelCurrentRequestForSession(widget.viewModel.sessionId);
}

const chatEditingService = accessor.get(IChatEditingService);
chatEditingService.currentAutoApplyOperation?.cancel();
}
});

0 comments on commit 6f3888b

Please sign in to comment.