From 62e077f66c995ba62e2d50094b4d7e1dd4d43de5 Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Fri, 3 Jan 2025 13:58:02 +0400 Subject: [PATCH 01/13] Fixing and simplifying New Chat keybindings logic --- vscode/package.json | 32 ++------------- vscode/src/chat/chat-view/ChatController.ts | 9 +++++ vscode/src/chat/chat-view/ChatsController.ts | 42 ++++++++------------ 3 files changed, 28 insertions(+), 55 deletions(-) diff --git a/vscode/package.json b/vscode/package.json index 5e5a4e9a4ff0..9e5c511de354 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -608,36 +608,10 @@ "when": "!cody.activated" }, { - "command": "cody.chat.toggle", + "command": "cody.chat.simpleToggle", "key": "alt+l", - "when": "cody.activated && editorTextFocus", - "args": { - "editorFocus": true - } - }, - { - "command": "cody.chat.toggle", - "key": "alt+l", - "when": "cody.activated && !editorTextFocus", - "args": { - "editorFocus": false - } - }, - { - "command": "cody.chat.toggle", - "key": "alt+/", - "when": "cody.activated && editorTextFocus", - "args": { - "editorFocus": true - } - }, - { - "command": "cody.chat.toggle", - "key": "alt+/", - "when": "cody.activated && !editorTextFocus", - "args": { - "editorFocus": false - } + "mac": "alt+l", + "when": "cody.activated" }, { "command": "cody.mention.selection", diff --git a/vscode/src/chat/chat-view/ChatController.ts b/vscode/src/chat/chat-view/ChatController.ts index b42d1bcf3e95..f254e7e3c413 100644 --- a/vscode/src/chat/chat-view/ChatController.ts +++ b/vscode/src/chat/chat-view/ChatController.ts @@ -262,6 +262,15 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv ) } + public isFocused(): boolean { + if (!this.webviewPanelOrView) { + return false + } + return 'active' in this.webviewPanelOrView + ? this.webviewPanelOrView.active + : this.webviewPanelOrView.visible + } + /** * onDidReceiveMessage handles all user actions sent from the chat panel view. * @param message is the message from the view. diff --git a/vscode/src/chat/chat-view/ChatsController.ts b/vscode/src/chat/chat-view/ChatsController.ts index e3a346dc9a74..8132607cb9ae 100644 --- a/vscode/src/chat/chat-view/ChatsController.ts +++ b/vscode/src/chat/chat-view/ChatsController.ts @@ -193,33 +193,23 @@ export class ChatsController implements vscode.Disposable { } }), - vscode.commands.registerCommand( - 'cody.chat.toggle', - async (ops: { editorFocus: boolean }) => { - const modality = getNewChatLocation() - - if (ops.editorFocus) { - if (modality === 'sidebar') { - await vscode.commands.executeCommand('cody.chat.focus') - } else { - const editorView = this.activeEditor?.webviewPanelOrView - if (editorView) { - revealWebviewViewOrPanel(editorView) - } else { - vscode.commands.executeCommand('cody.chat.newEditorPanel') - } - } - } else { - if (modality === 'sidebar') { - await vscode.commands.executeCommand( - 'workbench.action.focusActiveEditorGroup' - ) - } else { - await vscode.commands.executeCommand('workbench.action.navigateEditorGroups') - } - } + vscode.commands.registerCommand('cody.chat.simpleToggle', async () => { + // Case 1: Sidebar is not visible - show it + if (!this.panel.isVisible()) { + await vscode.commands.executeCommand('cody.chat.focus') + return } - ), + + // Case 2: Sidebar is focused with empty input - hide it + if (this.panel.isVisible() && this.panel.isFocused() && this.panel.isEmpty()) { + await vscode.commands.executeCommand('workbench.action.closeSidebar') + return + } + + // Case 3: Sidebar is visible - start new chat + await this.panel.clearAndRestartSession() + await vscode.commands.executeCommand('cody.chat.focus') + }), vscode.commands.registerCommand('cody.chat.history.export', () => this.exportHistory()), vscode.commands.registerCommand('cody.chat.history.clear', arg => this.clearHistory(arg)), vscode.commands.registerCommand('cody.chat.history.delete', item => this.clearHistory(item)), From 7fa5bbd97d0b88974913785643420862f6d244a1 Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Fri, 3 Jan 2025 15:26:50 +0400 Subject: [PATCH 02/13] Fixing and simplifying New Chat keybindings logic --- vscode/package.json | 15 --------------- vscode/src/chat/chat-view/ChatsController.ts | 3 ++- vscode/src/commands/GhostHintDecorator.ts | 4 ++-- vscode/webviews/chat/components/WelcomeFooter.tsx | 2 +- 4 files changed, 5 insertions(+), 19 deletions(-) diff --git a/vscode/package.json b/vscode/package.json index 9e5c511de354..bddf2097aeed 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -618,21 +618,6 @@ "key": "shift+alt+l", "when": "cody.activated && editorTextFocus && editorHasSelection" }, - { - "command": "cody.mention.selection", - "key": "shift+alt+/", - "when": "cody.activated && editorTextFocus && editorHasSelection" - }, - { - "command": "cody.chat.new", - "key": "shift+alt+l", - "when": "cody.activated && !editorTextFocus" - }, - { - "command": "cody.chat.new", - "key": "shift+alt+/", - "when": "cody.activated && !editorTextFocus" - }, { "command": "cody.tutorial.chat", "key": "alt+l", diff --git a/vscode/src/chat/chat-view/ChatsController.ts b/vscode/src/chat/chat-view/ChatsController.ts index 8132607cb9ae..eed0ae03301f 100644 --- a/vscode/src/chat/chat-view/ChatsController.ts +++ b/vscode/src/chat/chat-view/ChatsController.ts @@ -202,7 +202,8 @@ export class ChatsController implements vscode.Disposable { // Case 2: Sidebar is focused with empty input - hide it if (this.panel.isVisible() && this.panel.isFocused() && this.panel.isEmpty()) { - await vscode.commands.executeCommand('workbench.action.closeSidebar') + await this.panel.clearAndRestartSession() + await vscode.commands.executeCommand('cody.chat.focus') return } diff --git a/vscode/src/commands/GhostHintDecorator.ts b/vscode/src/commands/GhostHintDecorator.ts index c531360e5fa0..2b5aef211fcf 100644 --- a/vscode/src/commands/GhostHintDecorator.ts +++ b/vscode/src/commands/GhostHintDecorator.ts @@ -15,7 +15,7 @@ import type { SyntaxNode } from 'web-tree-sitter' import { execQueryWrapper } from '../tree-sitter/query-sdk' const EDIT_SHORTCUT_LABEL = isMacOS() ? 'Opt+K' : 'Alt+K' -const CHAT_SHORTCUT_LABEL = isMacOS() ? 'Opt+L' : 'Alt+L' +const CHAT_SHORTCUT_LABEL = isMacOS() ? 'Shift+Opt+L' : 'Shift+Alt+L' const DOC_SHORTCUT_LABEL = isMacOS() ? 'Opt+D' : 'Alt+D' /** @@ -130,7 +130,7 @@ const HINT_DECORATIONS: Record< { text: string; decoration: vscode.TextEditorDecorationType } > = { EditOrChat: { - text: `${EDIT_SHORTCUT_LABEL} to Edit, ${CHAT_SHORTCUT_LABEL} to Chat`, + text: `${EDIT_SHORTCUT_LABEL} to Edit, ${CHAT_SHORTCUT_LABEL} to Add to Chat`, decoration: vscode.window.createTextEditorDecorationType({ isWholeLine: true, after: { diff --git a/vscode/webviews/chat/components/WelcomeFooter.tsx b/vscode/webviews/chat/components/WelcomeFooter.tsx index db41413ad4f8..4a8df965506a 100644 --- a/vscode/webviews/chat/components/WelcomeFooter.tsx +++ b/vscode/webviews/chat/components/WelcomeFooter.tsx @@ -30,7 +30,7 @@ const chatTips: ChatViewTip[] = [ vsCodeOnly: true, }, { - message: 'Start a new chat with ⇧ ⌥ L or switch to chat with ⌥ /', + message: 'Press ⌥ L to start a new chat or switch to chat view', icon: MessageSquarePlus, vsCodeOnly: false, }, From 46d78a1ab610481df70a4b39dbc92796c4edf52d Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Fri, 3 Jan 2025 15:37:00 +0400 Subject: [PATCH 03/13] Fixing and simplifying New Chat keybindings logic --- vscode/src/chat/chat-view/ChatsController.ts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/vscode/src/chat/chat-view/ChatsController.ts b/vscode/src/chat/chat-view/ChatsController.ts index eed0ae03301f..f2dd2ba525c9 100644 --- a/vscode/src/chat/chat-view/ChatsController.ts +++ b/vscode/src/chat/chat-view/ChatsController.ts @@ -194,20 +194,6 @@ export class ChatsController implements vscode.Disposable { }), vscode.commands.registerCommand('cody.chat.simpleToggle', async () => { - // Case 1: Sidebar is not visible - show it - if (!this.panel.isVisible()) { - await vscode.commands.executeCommand('cody.chat.focus') - return - } - - // Case 2: Sidebar is focused with empty input - hide it - if (this.panel.isVisible() && this.panel.isFocused() && this.panel.isEmpty()) { - await this.panel.clearAndRestartSession() - await vscode.commands.executeCommand('cody.chat.focus') - return - } - - // Case 3: Sidebar is visible - start new chat await this.panel.clearAndRestartSession() await vscode.commands.executeCommand('cody.chat.focus') }), From f0f8d21e08f8fcbe92e78ad4f5cbc316f4206633 Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Fri, 3 Jan 2025 15:49:54 +0400 Subject: [PATCH 04/13] Fixing and simplifying New Chat keybindings logic --- vscode/src/chat/chat-view/ChatController.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/vscode/src/chat/chat-view/ChatController.ts b/vscode/src/chat/chat-view/ChatController.ts index f254e7e3c413..b42d1bcf3e95 100644 --- a/vscode/src/chat/chat-view/ChatController.ts +++ b/vscode/src/chat/chat-view/ChatController.ts @@ -262,15 +262,6 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv ) } - public isFocused(): boolean { - if (!this.webviewPanelOrView) { - return false - } - return 'active' in this.webviewPanelOrView - ? this.webviewPanelOrView.active - : this.webviewPanelOrView.visible - } - /** * onDidReceiveMessage handles all user actions sent from the chat panel view. * @param message is the message from the view. From 19b3e7ee2e964b03e578996370dd490a5ab9c52e Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Fri, 3 Jan 2025 15:52:18 +0400 Subject: [PATCH 05/13] Fixing and simplifying New Chat keybindings logic --- vscode/package.json | 2 +- vscode/src/chat/chat-view/ChatsController.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vscode/package.json b/vscode/package.json index bddf2097aeed..7706d172cb2b 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -608,7 +608,7 @@ "when": "!cody.activated" }, { - "command": "cody.chat.simpleToggle", + "command": "cody.chat.simpleNewChat", "key": "alt+l", "mac": "alt+l", "when": "cody.activated" diff --git a/vscode/src/chat/chat-view/ChatsController.ts b/vscode/src/chat/chat-view/ChatsController.ts index f2dd2ba525c9..23731b3b6161 100644 --- a/vscode/src/chat/chat-view/ChatsController.ts +++ b/vscode/src/chat/chat-view/ChatsController.ts @@ -193,7 +193,7 @@ export class ChatsController implements vscode.Disposable { } }), - vscode.commands.registerCommand('cody.chat.simpleToggle', async () => { + vscode.commands.registerCommand('cody.chat.simpleNewChat', async () => { await this.panel.clearAndRestartSession() await vscode.commands.executeCommand('cody.chat.focus') }), From f09f67ddf611160c9bd30831ab320608d7e29459 Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Sun, 5 Jan 2025 13:23:39 +0400 Subject: [PATCH 06/13] Fixing and simplifying New Chat keybindings logic --- vscode/package.json | 4 ++-- vscode/src/chat/chat-view/ChatController.ts | 7 +++++++ vscode/src/chat/chat-view/ChatsController.ts | 5 ++--- vscode/src/chat/protocol.ts | 1 + vscode/webviews/App.tsx | 12 ++++++++++++ vscode/webviews/chat/Transcript.tsx | 2 ++ 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/vscode/package.json b/vscode/package.json index 7706d172cb2b..21ce15ce42ef 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -611,11 +611,11 @@ "command": "cody.chat.simpleNewChat", "key": "alt+l", "mac": "alt+l", - "when": "cody.activated" + "when": "cody.activated && !editorHasSelection" }, { "command": "cody.mention.selection", - "key": "shift+alt+l", + "key": "alt+l", "when": "cody.activated && editorTextFocus && editorHasSelection" }, { diff --git a/vscode/src/chat/chat-view/ChatController.ts b/vscode/src/chat/chat-view/ChatController.ts index b42d1bcf3e95..8b1464262224 100644 --- a/vscode/src/chat/chat-view/ChatController.ts +++ b/vscode/src/chat/chat-view/ChatController.ts @@ -1193,6 +1193,12 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv this.syncPanelTitle() } + + public postClearChat(): void { + void this.postMessage({ + type: 'clearchat', + }) + } private syncPanelTitle() { // Update webview panel title if we're in an editor panel if (this._webviewPanelOrView && 'reveal' in this._webviewPanelOrView) { @@ -1572,6 +1578,7 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv } public isEmpty(): boolean { + this.chatBuilder.getMessages() return this.chatBuilder.isEmpty() } diff --git a/vscode/src/chat/chat-view/ChatsController.ts b/vscode/src/chat/chat-view/ChatsController.ts index 23731b3b6161..334a93897ba9 100644 --- a/vscode/src/chat/chat-view/ChatsController.ts +++ b/vscode/src/chat/chat-view/ChatsController.ts @@ -7,7 +7,7 @@ import { type ChatClient, DEFAULT_EVENT_SOURCE, type Guardrails, - type PromptMode, + PromptMode, authStatus, currentAuthStatus, currentAuthStatusAuthed, @@ -192,9 +192,8 @@ export class ChatsController implements vscode.Disposable { return vscode.commands.executeCommand('cody.chat.newPanel', args) } }), - vscode.commands.registerCommand('cody.chat.simpleNewChat', async () => { - await this.panel.clearAndRestartSession() + await this.executePrompt({ text: '', mode: PromptMode.CHAT, autoSubmit: false }) await vscode.commands.executeCommand('cody.chat.focus') }), vscode.commands.registerCommand('cody.chat.history.export', () => this.exportHistory()), diff --git a/vscode/src/chat/protocol.ts b/vscode/src/chat/protocol.ts index f7004c609cb2..bb19c6deefa6 100644 --- a/vscode/src/chat/protocol.ts +++ b/vscode/src/chat/protocol.ts @@ -177,6 +177,7 @@ export type ExtensionMessage = cssVariables: CodyIDECssVariables } | ({ type: 'transcript' } & ExtensionTranscriptMessage) + | { type: 'clearchat' } | { type: 'view'; view: View } | { type: 'errors'; errors: string } | { diff --git a/vscode/webviews/App.tsx b/vscode/webviews/App.tsx index d3fc84f3b5e9..a2f843311338 100644 --- a/vscode/webviews/App.tsx +++ b/vscode/webviews/App.tsx @@ -79,6 +79,18 @@ export const App: React.FunctionComponent<{ vscodeAPI: VSCodeWrapper }> = ({ vsc vscodeAPI.setState(message.chatID) break } + case 'clearchat': { + setTranscript([]) + setMessageInProgress(null) + vscodeAPI.setState(null) + // Clear the editor state + const editor = document.querySelector('[contenteditable="true"]') as HTMLElement + if (editor) { + editor.innerHTML = '' + } + debugger + break + } case 'config': setConfig(message) updateDisplayPathEnvInfoForWebview(message.workspaceFolderUris) diff --git a/vscode/webviews/chat/Transcript.tsx b/vscode/webviews/chat/Transcript.tsx index a39498be469b..f16288ecd75b 100644 --- a/vscode/webviews/chat/Transcript.tsx +++ b/vscode/webviews/chat/Transcript.tsx @@ -301,6 +301,7 @@ const TranscriptInteraction: FC = memo(props => { // Serialize the editor value after starting the span const editorValue = humanEditorRef.current?.getSerializedValue() + if (!editorValue) { console.error('Failed to serialize editor value') return @@ -535,6 +536,7 @@ const TranscriptInteraction: FC = memo(props => { const { corpusContext: corpusContextItems } = useDefaultContextForChat() const resubmitWithRepoContext = useCallback(async () => { const editorState = humanEditorRef.current?.getSerializedValue() + debugger if (editorState) { const editor = humanEditorRef.current if (corpusContextItems.length === 0 || !editor) { From 50e5a4ee3de9a4246633ad781e69c213772526a7 Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Sun, 5 Jan 2025 13:27:15 +0400 Subject: [PATCH 07/13] Fixing and simplifying New Chat keybindings logic --- vscode/src/chat/chat-view/ChatController.ts | 7 ------- vscode/src/chat/protocol.ts | 1 - vscode/webviews/App.tsx | 12 ------------ vscode/webviews/chat/Transcript.tsx | 1 - 4 files changed, 21 deletions(-) diff --git a/vscode/src/chat/chat-view/ChatController.ts b/vscode/src/chat/chat-view/ChatController.ts index 8b1464262224..b42d1bcf3e95 100644 --- a/vscode/src/chat/chat-view/ChatController.ts +++ b/vscode/src/chat/chat-view/ChatController.ts @@ -1193,12 +1193,6 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv this.syncPanelTitle() } - - public postClearChat(): void { - void this.postMessage({ - type: 'clearchat', - }) - } private syncPanelTitle() { // Update webview panel title if we're in an editor panel if (this._webviewPanelOrView && 'reveal' in this._webviewPanelOrView) { @@ -1578,7 +1572,6 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv } public isEmpty(): boolean { - this.chatBuilder.getMessages() return this.chatBuilder.isEmpty() } diff --git a/vscode/src/chat/protocol.ts b/vscode/src/chat/protocol.ts index bb19c6deefa6..f7004c609cb2 100644 --- a/vscode/src/chat/protocol.ts +++ b/vscode/src/chat/protocol.ts @@ -177,7 +177,6 @@ export type ExtensionMessage = cssVariables: CodyIDECssVariables } | ({ type: 'transcript' } & ExtensionTranscriptMessage) - | { type: 'clearchat' } | { type: 'view'; view: View } | { type: 'errors'; errors: string } | { diff --git a/vscode/webviews/App.tsx b/vscode/webviews/App.tsx index a2f843311338..d3fc84f3b5e9 100644 --- a/vscode/webviews/App.tsx +++ b/vscode/webviews/App.tsx @@ -79,18 +79,6 @@ export const App: React.FunctionComponent<{ vscodeAPI: VSCodeWrapper }> = ({ vsc vscodeAPI.setState(message.chatID) break } - case 'clearchat': { - setTranscript([]) - setMessageInProgress(null) - vscodeAPI.setState(null) - // Clear the editor state - const editor = document.querySelector('[contenteditable="true"]') as HTMLElement - if (editor) { - editor.innerHTML = '' - } - debugger - break - } case 'config': setConfig(message) updateDisplayPathEnvInfoForWebview(message.workspaceFolderUris) diff --git a/vscode/webviews/chat/Transcript.tsx b/vscode/webviews/chat/Transcript.tsx index f16288ecd75b..e2e74cd91b6d 100644 --- a/vscode/webviews/chat/Transcript.tsx +++ b/vscode/webviews/chat/Transcript.tsx @@ -536,7 +536,6 @@ const TranscriptInteraction: FC = memo(props => { const { corpusContext: corpusContextItems } = useDefaultContextForChat() const resubmitWithRepoContext = useCallback(async () => { const editorState = humanEditorRef.current?.getSerializedValue() - debugger if (editorState) { const editor = humanEditorRef.current if (corpusContextItems.length === 0 || !editor) { From 11cea674a6f444ae8a5b06a2f743c0fdf9978eba Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Sun, 5 Jan 2025 15:00:54 +0400 Subject: [PATCH 08/13] Fixing and simplifying New Chat keybindings logic --- vscode/package.json | 26 +++++++++++++++++++- vscode/src/chat/chat-view/ChatsController.ts | 12 ++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/vscode/package.json b/vscode/package.json index 21ce15ce42ef..3dcf56fd1e2e 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -608,11 +608,35 @@ "when": "!cody.activated" }, { - "command": "cody.chat.simpleNewChat", + "command": "cody.chat.toggle", "key": "alt+l", "mac": "alt+l", "when": "cody.activated && !editorHasSelection" }, + { + "command": "cody.chat.toggle", + "key": "alt+l", + "when": "cody.activated && !editorTextFocus", + "args": { + "editorFocus": false + } + }, + { + "command": "cody.chat.toggle", + "key": "alt+l", + "when": "cody.activated && editorTextFocus", + "args": { + "editorFocus": true + } + }, + { + "command": "cody.chat.toggle", + "key": "alt+l", + "when": "cody.activated && !editorTextFocus", + "args": { + "editorFocus": false + } + }, { "command": "cody.mention.selection", "key": "alt+l", diff --git a/vscode/src/chat/chat-view/ChatsController.ts b/vscode/src/chat/chat-view/ChatsController.ts index 334a93897ba9..e71b3d4a3256 100644 --- a/vscode/src/chat/chat-view/ChatsController.ts +++ b/vscode/src/chat/chat-view/ChatsController.ts @@ -123,6 +123,7 @@ export class ChatsController implements vscode.Disposable { ) } + public registerViewsAndCommands() { this.disposables.push( vscode.window.registerWebviewViewProvider('cody.chat', this.panel, { @@ -141,7 +142,6 @@ export class ChatsController implements vscode.Disposable { return undefined } } - this.disposables.push( vscode.commands.registerCommand('cody.chat.moveToEditor', async () => { localStorage.setLastUsedChatModality('editor') @@ -192,9 +192,15 @@ export class ChatsController implements vscode.Disposable { return vscode.commands.executeCommand('cody.chat.newPanel', args) } }), - vscode.commands.registerCommand('cody.chat.simpleNewChat', async () => { - await this.executePrompt({ text: '', mode: PromptMode.CHAT, autoSubmit: false }) + vscode.commands.registerCommand('cody.chat.toggle', async (uri: URI) => { + if (this.panel.isEmpty()) { + await this.executePrompt({ text: '', mode: PromptMode.CHAT, autoSubmit: false }) + } + else { + vscode.commands.executeCommand('cody.chat.newPanel') + } await vscode.commands.executeCommand('cody.chat.focus') + this.sendEditorContextToChat(uri) }), vscode.commands.registerCommand('cody.chat.history.export', () => this.exportHistory()), vscode.commands.registerCommand('cody.chat.history.clear', arg => this.clearHistory(arg)), From 59b79ef04909b07b52d4731f66a2b490b8d5cd12 Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Sun, 5 Jan 2025 16:28:28 +0400 Subject: [PATCH 09/13] Fixing and simplifying New Chat keybindings logic --- vscode/package.json | 2 +- vscode/src/chat/chat-view/ChatsController.ts | 20 +++++++++++++++---- vscode/src/chat/protocol.ts | 1 + vscode/src/commands/GhostHintDecorator.ts | 4 ++-- vscode/webviews/chat/Transcript.tsx | 1 - .../human/editor/HumanMessageEditor.tsx | 18 +++++++++++++++++ 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/vscode/package.json b/vscode/package.json index 3dcf56fd1e2e..8e6012c8a881 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -639,7 +639,7 @@ }, { "command": "cody.mention.selection", - "key": "alt+l", + "key": "alt+shift+l", "when": "cody.activated && editorTextFocus && editorHasSelection" }, { diff --git a/vscode/src/chat/chat-view/ChatsController.ts b/vscode/src/chat/chat-view/ChatsController.ts index e71b3d4a3256..4bd3bc0181ba 100644 --- a/vscode/src/chat/chat-view/ChatsController.ts +++ b/vscode/src/chat/chat-view/ChatsController.ts @@ -7,7 +7,7 @@ import { type ChatClient, DEFAULT_EVENT_SOURCE, type Guardrails, - PromptMode, + type PromptMode, authStatus, currentAuthStatus, currentAuthStatusAuthed, @@ -123,6 +123,19 @@ export class ChatsController implements vscode.Disposable { ) } + public async clearEditorText(): Promise { + const webviewPanelOrView = + this.panel.webviewPanelOrView || (await this.panel.createWebviewViewOrPanel()) + + setTimeout( + () => + webviewPanelOrView.webview.postMessage({ + type: 'clientAction', + clearEditorText: true, + }), + 1000 + ) + } public registerViewsAndCommands() { this.disposables.push( @@ -194,9 +207,8 @@ export class ChatsController implements vscode.Disposable { }), vscode.commands.registerCommand('cody.chat.toggle', async (uri: URI) => { if (this.panel.isEmpty()) { - await this.executePrompt({ text: '', mode: PromptMode.CHAT, autoSubmit: false }) - } - else { + await this.clearEditorText() + } else { vscode.commands.executeCommand('cody.chat.newPanel') } await vscode.commands.executeCommand('cody.chat.focus') diff --git a/vscode/src/chat/protocol.ts b/vscode/src/chat/protocol.ts index f7004c609cb2..7012d90e308e 100644 --- a/vscode/src/chat/protocol.ts +++ b/vscode/src/chat/protocol.ts @@ -190,6 +190,7 @@ export type ExtensionMessage = | { text: string; mode?: PromptMode | undefined | null; autoSubmit: boolean } | undefined | null + clearEditorText?: boolean | undefined | null } | ({ type: 'attribution' } & ExtensionAttributionMessage) | { type: 'rpc/response'; message: ResponseMessage } diff --git a/vscode/src/commands/GhostHintDecorator.ts b/vscode/src/commands/GhostHintDecorator.ts index 2b5aef211fcf..c531360e5fa0 100644 --- a/vscode/src/commands/GhostHintDecorator.ts +++ b/vscode/src/commands/GhostHintDecorator.ts @@ -15,7 +15,7 @@ import type { SyntaxNode } from 'web-tree-sitter' import { execQueryWrapper } from '../tree-sitter/query-sdk' const EDIT_SHORTCUT_LABEL = isMacOS() ? 'Opt+K' : 'Alt+K' -const CHAT_SHORTCUT_LABEL = isMacOS() ? 'Shift+Opt+L' : 'Shift+Alt+L' +const CHAT_SHORTCUT_LABEL = isMacOS() ? 'Opt+L' : 'Alt+L' const DOC_SHORTCUT_LABEL = isMacOS() ? 'Opt+D' : 'Alt+D' /** @@ -130,7 +130,7 @@ const HINT_DECORATIONS: Record< { text: string; decoration: vscode.TextEditorDecorationType } > = { EditOrChat: { - text: `${EDIT_SHORTCUT_LABEL} to Edit, ${CHAT_SHORTCUT_LABEL} to Add to Chat`, + text: `${EDIT_SHORTCUT_LABEL} to Edit, ${CHAT_SHORTCUT_LABEL} to Chat`, decoration: vscode.window.createTextEditorDecorationType({ isWholeLine: true, after: { diff --git a/vscode/webviews/chat/Transcript.tsx b/vscode/webviews/chat/Transcript.tsx index e2e74cd91b6d..a39498be469b 100644 --- a/vscode/webviews/chat/Transcript.tsx +++ b/vscode/webviews/chat/Transcript.tsx @@ -301,7 +301,6 @@ const TranscriptInteraction: FC = memo(props => { // Serialize the editor value after starting the span const editorValue = humanEditorRef.current?.getSerializedValue() - if (!editorValue) { console.error('Failed to serialize editor value') return diff --git a/vscode/webviews/chat/cells/messageCell/human/editor/HumanMessageEditor.tsx b/vscode/webviews/chat/cells/messageCell/human/editor/HumanMessageEditor.tsx index 9683d4e35ed2..83f7ba7f5050 100644 --- a/vscode/webviews/chat/cells/messageCell/human/editor/HumanMessageEditor.tsx +++ b/vscode/webviews/chat/cells/messageCell/human/editor/HumanMessageEditor.tsx @@ -299,6 +299,7 @@ export const HumanMessageEditor: FunctionComponent<{ submitHumanInput, setLastHumanInputIntent, setPromptAsInput, + clearEditorText, }) => { const updates: Promise[] = [] @@ -349,6 +350,23 @@ export const HumanMessageEditor: FunctionComponent<{ let promptIntent = undefined + if (clearEditorText) { + updates.push( + new Promise(async resolve => { + const { initialContext } = await firstValueFrom( + extensionAPI.defaultContext().pipe(skipPendingOperation()) + ) + const emptyState = await firstValueFrom( + extensionAPI.hydratePromptMessage('', initialContext) + ) + if (editorRef.current) { + editorRef.current.setEditorState(emptyState) + } + resolve() + }) + ) + } + if (setPromptAsInput) { // set the intent promptIntent = promptModeToIntent(setPromptAsInput.mode) From 855693dbf94abc1933a3d339549bbb489649ae09 Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Sun, 5 Jan 2025 16:29:25 +0400 Subject: [PATCH 10/13] Fixing and simplifying New Chat keybindings logic --- vscode/package.json | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vscode/package.json b/vscode/package.json index 8e6012c8a881..71bf3c2fe060 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -642,6 +642,16 @@ "key": "alt+shift+l", "when": "cody.activated && editorTextFocus && editorHasSelection" }, + { + "command": "cody.chat.new", + "key": "shift+alt+l", + "when": "cody.activated && !editorTextFocus" + }, + { + "command": "cody.chat.new", + "key": "shift+alt+/", + "when": "cody.activated && !editorTextFocus" + }, { "command": "cody.tutorial.chat", "key": "alt+l", From 3bca7c8d23a58f7296cf323612367ee1a87a9f21 Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Sun, 5 Jan 2025 17:19:48 +0400 Subject: [PATCH 11/13] Fixing and simplifying New Chat keybindings logic --- vscode/package.json | 30 ++++++++++----- vscode/src/chat/chat-view/ChatsController.ts | 37 ++++++++++--------- .../human/editor/HumanMessageEditor.tsx | 23 +++++++----- 3 files changed, 53 insertions(+), 37 deletions(-) diff --git a/vscode/package.json b/vscode/package.json index 71bf3c2fe060..f563c04e6d61 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -611,7 +611,19 @@ "command": "cody.chat.toggle", "key": "alt+l", "mac": "alt+l", - "when": "cody.activated && !editorHasSelection" + "when": "cody.activated && editorHasSelection", + "args": { + "editorFocus": true + } + }, + { + "command": "cody.chat.toggle", + "key": "alt+l", + "mac": "alt+l", + "when": "cody.activated && !editorHasSelection", + "args": { + "editorFocus": true + } }, { "command": "cody.chat.toggle", @@ -643,14 +655,14 @@ "when": "cody.activated && editorTextFocus && editorHasSelection" }, { - "command": "cody.chat.new", - "key": "shift+alt+l", - "when": "cody.activated && !editorTextFocus" - }, - { - "command": "cody.chat.new", - "key": "shift+alt+/", - "when": "cody.activated && !editorTextFocus" + "command": "cody.chat.new", + "key": "shift+alt+l", + "when": "cody.activated && !editorTextFocus" + }, + { + "command": "cody.chat.new", + "key": "shift+alt+/", + "when": "cody.activated && !editorTextFocus" }, { "command": "cody.tutorial.chat", diff --git a/vscode/src/chat/chat-view/ChatsController.ts b/vscode/src/chat/chat-view/ChatsController.ts index 4bd3bc0181ba..ed0bb62178bd 100644 --- a/vscode/src/chat/chat-view/ChatsController.ts +++ b/vscode/src/chat/chat-view/ChatsController.ts @@ -124,17 +124,15 @@ export class ChatsController implements vscode.Disposable { } public async clearEditorText(): Promise { - const webviewPanelOrView = - this.panel.webviewPanelOrView || (await this.panel.createWebviewViewOrPanel()) + const webviewPanelOrView = this.panel.webviewPanelOrView + if (!webviewPanelOrView) { + return + } - setTimeout( - () => - webviewPanelOrView.webview.postMessage({ - type: 'clientAction', - clearEditorText: true, - }), - 1000 - ) + webviewPanelOrView.webview.postMessage({ + type: 'clientAction', + clearEditorText: true, + }) } public registerViewsAndCommands() { @@ -205,15 +203,18 @@ export class ChatsController implements vscode.Disposable { return vscode.commands.executeCommand('cody.chat.newPanel', args) } }), - vscode.commands.registerCommand('cody.chat.toggle', async (uri: URI) => { - if (this.panel.isEmpty()) { - await this.clearEditorText() - } else { - vscode.commands.executeCommand('cody.chat.newPanel') + vscode.commands.registerCommand( + 'cody.chat.toggle', + async (args: { uri: URI; editorFocus: boolean }) => { + if (this.panel.isEmpty() && !args.editorFocus) { + await this.clearEditorText() + } else { + vscode.commands.executeCommand('cody.chat.newPanel') + } + await vscode.commands.executeCommand('cody.chat.focus') + this.sendEditorContextToChat(args.uri) } - await vscode.commands.executeCommand('cody.chat.focus') - this.sendEditorContextToChat(uri) - }), + ), vscode.commands.registerCommand('cody.chat.history.export', () => this.exportHistory()), vscode.commands.registerCommand('cody.chat.history.clear', arg => this.clearHistory(arg)), vscode.commands.registerCommand('cody.chat.history.delete', item => this.clearHistory(item)), diff --git a/vscode/webviews/chat/cells/messageCell/human/editor/HumanMessageEditor.tsx b/vscode/webviews/chat/cells/messageCell/human/editor/HumanMessageEditor.tsx index 83f7ba7f5050..e0ae0566cb77 100644 --- a/vscode/webviews/chat/cells/messageCell/human/editor/HumanMessageEditor.tsx +++ b/vscode/webviews/chat/cells/messageCell/human/editor/HumanMessageEditor.tsx @@ -352,17 +352,20 @@ export const HumanMessageEditor: FunctionComponent<{ if (clearEditorText) { updates.push( - new Promise(async resolve => { - const { initialContext } = await firstValueFrom( + new Promise(resolve => { + firstValueFrom( extensionAPI.defaultContext().pipe(skipPendingOperation()) - ) - const emptyState = await firstValueFrom( - extensionAPI.hydratePromptMessage('', initialContext) - ) - if (editorRef.current) { - editorRef.current.setEditorState(emptyState) - } - resolve() + ).then(({ initialContext }) => { + firstValueFrom( + extensionAPI.hydratePromptMessage('', initialContext) + ).then(emptyState => { + if (editorRef.current) { + editorRef.current.setEditorState(emptyState) + editorRef.current.setFocus(true) + } + resolve() + }) + }) }) ) } From e5d7d3f6d78dee3e61b2cf33635e4a6765bd9168 Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Sun, 5 Jan 2025 17:37:54 +0400 Subject: [PATCH 12/13] Fixing and simplifying New Chat keybindings logic --- vscode/package.json | 7 +------ vscode/src/chat/chat-view/ChatsController.ts | 6 +++--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/vscode/package.json b/vscode/package.json index f563c04e6d61..10b2deb6afc3 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -656,12 +656,7 @@ }, { "command": "cody.chat.new", - "key": "shift+alt+l", - "when": "cody.activated && !editorTextFocus" - }, - { - "command": "cody.chat.new", - "key": "shift+alt+/", + "key": "alt+l", "when": "cody.activated && !editorTextFocus" }, { diff --git a/vscode/src/chat/chat-view/ChatsController.ts b/vscode/src/chat/chat-view/ChatsController.ts index ed0bb62178bd..27d7fdca5f04 100644 --- a/vscode/src/chat/chat-view/ChatsController.ts +++ b/vscode/src/chat/chat-view/ChatsController.ts @@ -200,19 +200,19 @@ export class ChatsController implements vscode.Disposable { case 'editor': return vscode.commands.executeCommand('cody.chat.newEditorPanel', args) case 'sidebar': - return vscode.commands.executeCommand('cody.chat.newPanel', args) + return vscode.commands.executeCommand('cody.chat.toggle', args) } }), vscode.commands.registerCommand( 'cody.chat.toggle', async (args: { uri: URI; editorFocus: boolean }) => { - if (this.panel.isEmpty() && !args.editorFocus) { + if (this.panel.isEmpty() && !args?.editorFocus) { await this.clearEditorText() } else { vscode.commands.executeCommand('cody.chat.newPanel') } await vscode.commands.executeCommand('cody.chat.focus') - this.sendEditorContextToChat(args.uri) + this.sendEditorContextToChat(args?.uri) } ), vscode.commands.registerCommand('cody.chat.history.export', () => this.exportHistory()), From 4ab276dc09ecf7cfda83ea090644e9424b1c1489 Mon Sep 17 00:00:00 2001 From: arafatkatze Date: Mon, 6 Jan 2025 17:08:00 +0400 Subject: [PATCH 13/13] Fixing and simplifying New Chat keybindings logic --- vscode/package.json | 2 +- vscode/webviews/tabs/utils.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vscode/package.json b/vscode/package.json index 10b2deb6afc3..1cd40784976f 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -622,7 +622,7 @@ "mac": "alt+l", "when": "cody.activated && !editorHasSelection", "args": { - "editorFocus": true + "editorFocus": false } }, { diff --git a/vscode/webviews/tabs/utils.ts b/vscode/webviews/tabs/utils.ts index af547b7e142c..d645d0fd59e9 100644 --- a/vscode/webviews/tabs/utils.ts +++ b/vscode/webviews/tabs/utils.ts @@ -20,6 +20,6 @@ export function getCreateNewChatCommand(options: NewChatCommandInput): string { return IDE === CodyIDE.Web ? 'cody.chat.new' : webviewType === 'sidebar' || !multipleWebviewsEnabled - ? 'cody.chat.newPanel' + ? 'cody.chat.toggle' : 'cody.chat.newEditorPanel' }