From d87b7c5801a55715c29ec9d4d822a1d3e64f9243 Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Wed, 7 Feb 2024 17:37:02 +0800 Subject: [PATCH] feat: Implement shortcut for DevChat input focus - Added keybindings for DevChat input focus shortcut - Implemented focusHandler to focus on DevChat input upon shortcut --- package.json | 9 ++++++++- src/contributes/commands.ts | 2 ++ src/handler/focusHandler.ts | 10 ++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/handler/focusHandler.ts diff --git a/package.json b/package.json index beac802..6cf2f16 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "devchat", "displayName": "DevChat", "description": "Write prompts, not code", - "version": "0.1.55", + "version": "0.1.65", "icon": "assets/devchat.png", "publisher": "merico", "engines": { @@ -670,6 +670,13 @@ "category": "DevChat" } ], + "keybindings": [ + { + "command": "devchat.openChatPanel", + "key": "ctrl+shift+/", + "mac": "cmd+shift+/" + } + ], "menus": { "editor/title": [ { diff --git a/src/contributes/commands.ts b/src/contributes/commands.ts index 74a4170..4de2f18 100644 --- a/src/contributes/commands.ts +++ b/src/contributes/commands.ts @@ -17,6 +17,7 @@ import DevChat from "../toolwrapper/devchat"; import { createEnvByConda, createEnvByMamba } from '../util/python_installer/app_install'; import { installRequirements } from '../util/python_installer/package_install'; import { chatWithDevChat } from '../handler/chatHandler'; +import { focusDevChatInput } from '../handler/focusHandler'; const readdir = util.promisify(fs.readdir); const stat = util.promisify(fs.stat); @@ -42,6 +43,7 @@ async function copyDirectory(src: string, dest: string): Promise { function registerOpenChatPanelCommand(context: vscode.ExtensionContext) { let disposable = vscode.commands.registerCommand('devchat.openChatPanel', async () => { await vscode.commands.executeCommand('devchat-view.focus'); + await focusDevChatInput(ExtensionContextHolder.provider?.view()!); }); context.subscriptions.push(disposable); } diff --git a/src/handler/focusHandler.ts b/src/handler/focusHandler.ts new file mode 100644 index 0000000..1388669 --- /dev/null +++ b/src/handler/focusHandler.ts @@ -0,0 +1,10 @@ +import * as vscode from 'vscode'; +import { MessageHandler } from './messageHandler'; + + +export async function focusDevChatInput(panel: vscode.WebviewPanel|vscode.WebviewView): Promise { + const inputFocusMessage = {"command": "focusDevChatInput"}; + if (panel) { + MessageHandler.sendMessage(panel, inputFocusMessage); + } +}