Skip to content

Commit

Permalink
Enable cmd+up to focus chat list in terminal and inline chat widgets (m…
Browse files Browse the repository at this point in the history
…icrosoft#224645)

* Enable cmd+up to focus chat list in terminal and inline chat widgets
Fix microsoft#218088

* Clean up
  • Loading branch information
roblourens authored Aug 2, 2024
1 parent 70c640b commit c21836e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
5 changes: 2 additions & 3 deletions src/vs/workbench/contrib/chat/browser/actions/chatActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import { CHAT_VIEW_ID, IChatWidgetService, showChatView } from 'vs/workbench/con
import { IChatEditorOptions } from 'vs/workbench/contrib/chat/browser/chatEditor';
import { ChatEditorInput } from 'vs/workbench/contrib/chat/browser/chatEditorInput';
import { ChatViewPane } from 'vs/workbench/contrib/chat/browser/chatViewPane';
import { ChatAgentLocation } from 'vs/workbench/contrib/chat/common/chatAgents';
import { CONTEXT_CHAT_ENABLED, CONTEXT_CHAT_INPUT_CURSOR_AT_TOP, CONTEXT_CHAT_LOCATION, CONTEXT_IN_CHAT_INPUT, CONTEXT_IN_CHAT_SESSION } from 'vs/workbench/contrib/chat/common/chatContextKeys';
import { CONTEXT_CHAT_ENABLED, CONTEXT_CHAT_INPUT_CURSOR_AT_TOP, CONTEXT_IN_CHAT_INPUT, CONTEXT_IN_CHAT_SESSION } from 'vs/workbench/contrib/chat/common/chatContextKeys';
import { IChatDetail, IChatService } from 'vs/workbench/contrib/chat/common/chatService';
import { IChatRequestViewModel, IChatResponseViewModel, isRequestVM } from 'vs/workbench/contrib/chat/common/chatViewModel';
import { IChatWidgetHistoryService } from 'vs/workbench/contrib/chat/common/chatWidgetHistoryService';
Expand Down Expand Up @@ -259,7 +258,7 @@ export function registerChatActions() {
super({
id: 'chat.action.focus',
title: localize2('actions.interactiveSession.focus', 'Focus Chat List'),
precondition: ContextKeyExpr.and(CONTEXT_IN_CHAT_INPUT, CONTEXT_CHAT_LOCATION.isEqualTo(ChatAgentLocation.Panel)),
precondition: ContextKeyExpr.and(CONTEXT_IN_CHAT_INPUT),
category: CHAT_CATEGORY,
keybinding: [
// On mac, require that the cursor is at the top of the input, to avoid stealing cmd+up to move the cursor to the top
Expand Down
32 changes: 20 additions & 12 deletions src/vs/workbench/contrib/chat/browser/chatInputPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,18 +432,6 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge

this._onDidBlur.fire();
}));
this._register(this._inputEditor.onDidChangeCursorPosition(e => {
const model = this._inputEditor.getModel();
if (!model) {
return;
}

const atTop = e.position.column === 1 && e.position.lineNumber === 1;
this.chatCursorAtTop.set(atTop);

this.historyNavigationBackwardsEnablement.set(atTop);
this.historyNavigationForewardsEnablement.set(e.position.equals(getLastPosition(model)));
}));

this.toolbar = this._register(this.instantiationService.createInstance(MenuWorkbenchToolBar, inputContainer, this.options.menus.executeToolbar, {
telemetrySource: this.options.menus.telemetrySource,
Expand Down Expand Up @@ -496,6 +484,26 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
const lineNumber = this.inputModel.getLineCount();
this._inputEditor.setPosition({ lineNumber, column: this.inputModel.getLineMaxColumn(lineNumber) });
}

const onDidChangeCursorPosition = () => {
const model = this._inputEditor.getModel();
if (!model) {
return;
}

const position = this._inputEditor.getPosition();
if (!position) {
return;
}

const atTop = position.column === 1 && position.lineNumber === 1;
this.chatCursorAtTop.set(atTop);

this.historyNavigationBackwardsEnablement.set(atTop);
this.historyNavigationForewardsEnablement.set(position.equals(getLastPosition(model)));
};
this._register(this._inputEditor.onDidChangeCursorPosition(e => onDidChangeCursorPosition()));
onDidChangeCursorPosition();
}

private initAttachedContext(container: HTMLElement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { registerIcon } from 'vs/platform/theme/common/iconRegistry';
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { ILogService } from 'vs/platform/log/common/log';
import { IChatService } from 'vs/workbench/contrib/chat/common/chatService';
import { CONTEXT_IN_CHAT_INPUT } from 'vs/workbench/contrib/chat/common/chatContextKeys';

CommandsRegistry.registerCommandAlias('interactiveEditor.start', 'inlineChat.start');
CommandsRegistry.registerCommandAlias('interactive.acceptChanges', ACTION_ACCEPT_CHANGES);
Expand Down Expand Up @@ -504,6 +505,7 @@ export class ViewInChatAction extends AbstractInlineChatAction {
keybinding: {
weight: KeybindingWeight.WorkbenchContrib,
primary: KeyMod.CtrlCmd | KeyCode.DownArrow,
when: CONTEXT_IN_CHAT_INPUT
}
});
}
Expand Down

0 comments on commit c21836e

Please sign in to comment.