From 4535dc81807bc14ca29ea8d745b8bd48fcf0cf9d Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Wed, 6 Mar 2024 21:57:57 +0800 Subject: [PATCH] fix(gui): only trigger popup on '$' input #51 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, the popup was triggered on both '$' and '¥' characters, which was unnecessary and could lead to unexpected behavior. This commit fixes the issue by only triggering the popup on '$' input. Additionally, the focus is now requested for the input field after a variable is selected, ensuring that the user can continue typing without having to click back into the input field. --- .../devti/custom/compile/VariableTemplateCompiler.kt | 2 +- .../cc/unitmesh/devti/gui/chat/AutoDevInputSection.kt | 11 +++-------- .../cc/unitmesh/devti/provider/ContextPrompter.kt | 3 --- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/cc/unitmesh/devti/custom/compile/VariableTemplateCompiler.kt b/src/main/kotlin/cc/unitmesh/devti/custom/compile/VariableTemplateCompiler.kt index aa1c2e3f5a..e39249ac45 100644 --- a/src/main/kotlin/cc/unitmesh/devti/custom/compile/VariableTemplateCompiler.kt +++ b/src/main/kotlin/cc/unitmesh/devti/custom/compile/VariableTemplateCompiler.kt @@ -27,7 +27,7 @@ class VariableTemplateCompiler( private val velocityContext = VelocityContext() init { - this.set(CustomVariable.SELECTION.variable, selectedText) + this.set(CustomVariable.SELECTION.variable, editor.selectionModel.selectedText ?: selectedText) this.set(CustomVariable.BEFORE_CURSOR.variable, file.text.substring(0, editor.caretModel.offset)) this.set(CustomVariable.AFTER_CURSOR.variable, file.text.substring(editor.caretModel.offset)) } diff --git a/src/main/kotlin/cc/unitmesh/devti/gui/chat/AutoDevInputSection.kt b/src/main/kotlin/cc/unitmesh/devti/gui/chat/AutoDevInputSection.kt index 89d85bf072..0a3da1b90f 100644 --- a/src/main/kotlin/cc/unitmesh/devti/gui/chat/AutoDevInputSection.kt +++ b/src/main/kotlin/cc/unitmesh/devti/gui/chat/AutoDevInputSection.kt @@ -109,8 +109,7 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab revalidate() } - // check new input == $ - if (event.newFragment.contentEquals("$") || event.newFragment.contentEquals("¥")) { + if (event.newFragment.contentEquals("$")) { if (popup == null) { popup = createPopup() } @@ -199,8 +198,9 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab if (selectedItem != null) { text += "${selectedItem.customVariable.variable} " } + + this@AutoDevInputSection.input.requestFocus() this@AutoDevInputSection.popup?.cancel() - this@AutoDevInputSection.requestFocus() } KeyEvent.VK_DOWN -> { @@ -221,11 +221,6 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab list.setSelectedIndex(list.getItemsCount() - 1) } } - - // Esc - KeyEvent.VK_ESCAPE -> { - this@AutoDevInputSection.requestFocus() - } } } }) diff --git a/src/main/kotlin/cc/unitmesh/devti/provider/ContextPrompter.kt b/src/main/kotlin/cc/unitmesh/devti/provider/ContextPrompter.kt index d09365258e..f04d99049d 100644 --- a/src/main/kotlin/cc/unitmesh/devti/provider/ContextPrompter.kt +++ b/src/main/kotlin/cc/unitmesh/devti/provider/ContextPrompter.kt @@ -6,13 +6,11 @@ import cc.unitmesh.devti.provider.builtin.DefaultContextPrompter import cc.unitmesh.devti.provider.context.ChatContextProvider import cc.unitmesh.devti.provider.context.ChatCreationContext import cc.unitmesh.devti.settings.coder.coderSetting -import com.intellij.lang.html.HTMLLanguage import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.extensions.ExtensionPointName import com.intellij.openapi.fileEditor.FileEditorManager import com.intellij.openapi.project.Project import com.intellij.openapi.project.ProjectManager -import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile @@ -103,7 +101,6 @@ abstract class ContextPrompter : LazyExtensionInstance() { editor = editor, selectedText = selectedText ) - } companion object {