From 8227a95f5c80f6c5ec66195cefb53638c4d5555a Mon Sep 17 00:00:00 2001
From: niancpu <1756583517@qq.com>
Date: Wed, 10 Jun 2026 19:54:56 +0800
Subject: [PATCH] feat: add focus actions for Agent and Chat tool window inputs
Register two new actions (no default keybinding, not attached to any menu)
so users can assign their own shortcuts in Settings > Keymap:
- ProxyAI.FocusAgentInput: show tool window, switch to Agent tab, focus input
- ProxyAI.FocusChatInput: show tool window, switch to Chat tab, focus input
For Agent, AgentToolWindowPanel#focusActiveInput() prefers the landing
panel when present and falls back to the active tab; Chat reuses the
existing ChatToolWindowPanel#requestFocusForInput().
---
.../codegpt/actions/FocusAgentInputAction.kt | 29 +++++++++++++++++++
.../codegpt/actions/FocusChatInputAction.kt | 28 ++++++++++++++++++
.../toolwindow/agent/AgentToolWindowPanel.kt | 8 +++++
src/main/resources/META-INF/plugin.xml | 11 +++++++
4 files changed, 76 insertions(+)
create mode 100644 src/main/kotlin/ee/carlrobert/codegpt/actions/FocusAgentInputAction.kt
create mode 100644 src/main/kotlin/ee/carlrobert/codegpt/actions/FocusChatInputAction.kt
diff --git a/src/main/kotlin/ee/carlrobert/codegpt/actions/FocusAgentInputAction.kt b/src/main/kotlin/ee/carlrobert/codegpt/actions/FocusAgentInputAction.kt
new file mode 100644
index 000000000..9e47c199f
--- /dev/null
+++ b/src/main/kotlin/ee/carlrobert/codegpt/actions/FocusAgentInputAction.kt
@@ -0,0 +1,29 @@
+package ee.carlrobert.codegpt.actions
+
+import com.intellij.openapi.actionSystem.ActionUpdateThread
+import com.intellij.openapi.actionSystem.AnAction
+import com.intellij.openapi.actionSystem.AnActionEvent
+import com.intellij.openapi.wm.ToolWindowManager
+import ee.carlrobert.codegpt.toolwindow.agent.AgentToolWindowPanel
+
+class FocusAgentInputAction : AnAction() {
+
+ override fun update(e: AnActionEvent) {
+ e.presentation.isEnabled = e.project != null
+ }
+
+ override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
+
+ override fun actionPerformed(e: AnActionEvent) {
+ val project = e.project ?: return
+ val toolWindow = ToolWindowManager.getInstance(project).getToolWindow("ProxyAI") ?: return
+ toolWindow.show {
+ val contentManager = toolWindow.contentManager
+ val agentContent = contentManager.contents.firstOrNull { it.tabName == "Agent" }
+ ?: contentManager.getContent(0)
+ ?: return@show
+ contentManager.setSelectedContent(agentContent)
+ (agentContent.component as? AgentToolWindowPanel)?.focusActiveInput()
+ }
+ }
+}
diff --git a/src/main/kotlin/ee/carlrobert/codegpt/actions/FocusChatInputAction.kt b/src/main/kotlin/ee/carlrobert/codegpt/actions/FocusChatInputAction.kt
new file mode 100644
index 000000000..1d70b6b7a
--- /dev/null
+++ b/src/main/kotlin/ee/carlrobert/codegpt/actions/FocusChatInputAction.kt
@@ -0,0 +1,28 @@
+package ee.carlrobert.codegpt.actions
+
+import com.intellij.openapi.actionSystem.ActionUpdateThread
+import com.intellij.openapi.actionSystem.AnAction
+import com.intellij.openapi.actionSystem.AnActionEvent
+import com.intellij.openapi.wm.ToolWindowManager
+import ee.carlrobert.codegpt.toolwindow.chat.ChatToolWindowPanel
+
+class FocusChatInputAction : AnAction() {
+
+ override fun update(e: AnActionEvent) {
+ e.presentation.isEnabled = e.project != null
+ }
+
+ override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
+
+ override fun actionPerformed(e: AnActionEvent) {
+ val project = e.project ?: return
+ val toolWindow = ToolWindowManager.getInstance(project).getToolWindow("ProxyAI") ?: return
+ toolWindow.show {
+ val contentManager = toolWindow.contentManager
+ val chatContent = contentManager.contents.firstOrNull { it.tabName == "Chat" }
+ ?: return@show
+ contentManager.setSelectedContent(chatContent)
+ (chatContent.component as? ChatToolWindowPanel)?.requestFocusForInput()
+ }
+ }
+}
diff --git a/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/agent/AgentToolWindowPanel.kt b/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/agent/AgentToolWindowPanel.kt
index 84f5c483f..ee1952a2e 100644
--- a/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/agent/AgentToolWindowPanel.kt
+++ b/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/agent/AgentToolWindowPanel.kt
@@ -85,6 +85,14 @@ class AgentToolWindowPanel(
fun getTabbedPane(): AgentToolWindowTabbedPane = tabbedPane
+ fun focusActiveInput() {
+ landingPanel?.let {
+ it.requestFocusForTextArea()
+ return
+ }
+ contentManager.getActiveTabPanel()?.requestFocusForTextArea()
+ }
+
private fun showTabsView() {
disposeLandingPanel()
centerLayout.show(centerPanel, TABS_CARD)
diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml
index 1259f874c..47d85824b 100644
--- a/src/main/resources/META-INF/plugin.xml
+++ b/src/main/resources/META-INF/plugin.xml
@@ -319,6 +319,17 @@
+
+
+