Skip to content

Commit

Permalink
Fix "new chat" before focusing chat panel
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed May 25, 2024
1 parent 91b99e1 commit 8cba4fc
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/vs/workbench/contrib/chat/browser/actions/chatClearActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import { CHAT_CATEGORY, isChatViewTitleActionContext } from 'vs/workbench/contri
import { clearChatEditor } from 'vs/workbench/contrib/chat/browser/actions/chatClear';
import { CHAT_VIEW_ID, IChatWidgetService } from 'vs/workbench/contrib/chat/browser/chat';
import { ChatEditorInput } from 'vs/workbench/contrib/chat/browser/chatEditorInput';
import { ChatViewPane } from 'vs/workbench/contrib/chat/browser/chatViewPane';
import { CONTEXT_IN_CHAT_SESSION, CONTEXT_CHAT_ENABLED } from 'vs/workbench/contrib/chat/common/chatContextKeys';
import { IViewsService } from 'vs/workbench/services/views/common/viewsService';

export const ACTION_ID_NEW_CHAT = `workbench.action.chat.newChat`;

Expand All @@ -38,7 +40,7 @@ export function registerNewChatActions() {
});
}
async run(accessor: ServicesAccessor, ...args: any[]) {
announceChatCleared(accessor);
announceChatCleared(accessor.get(IAccessibilitySignalService));
await clearChatEditor(accessor);
}
});
Expand Down Expand Up @@ -73,29 +75,33 @@ export function registerNewChatActions() {
});
}

run(accessor: ServicesAccessor, ...args: any[]) {
async run(accessor: ServicesAccessor, ...args: any[]) {
const context = args[0];
const accessibilitySignalService = accessor.get(IAccessibilitySignalService);
if (isChatViewTitleActionContext(context)) {
// Is running in the Chat view title
announceChatCleared(accessor);
announceChatCleared(accessibilitySignalService);
context.chatView.clear();
context.chatView.widget.focusInput();
} else {
// Is running from f1 or keybinding
const widgetService = accessor.get(IChatWidgetService);
const viewsService = accessor.get(IViewsService);

const widget = widgetService.lastFocusedWidget;
let widget = widgetService.lastFocusedWidget;
if (!widget) {
return;
const chatView = await viewsService.openView(CHAT_VIEW_ID) as ChatViewPane;
widget = chatView.widget;
}
announceChatCleared(accessor);

announceChatCleared(accessibilitySignalService);
widget.clear();
widget.focusInput();
}
}
});
}

function announceChatCleared(accessor: ServicesAccessor): void {
accessor.get(IAccessibilitySignalService).playSignal(AccessibilitySignal.clear);
function announceChatCleared(accessibilitySignalService: IAccessibilitySignalService): void {
accessibilitySignalService.playSignal(AccessibilitySignal.clear);
}

0 comments on commit 8cba4fc

Please sign in to comment.