Skip to content

Commit 4535dc8

Browse files
committed
fix(gui): only trigger popup on '$' input #51
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.
1 parent 93a5e52 commit 4535dc8

File tree

3 files changed

+4
-12
lines changed

3 files changed

+4
-12
lines changed

src/main/kotlin/cc/unitmesh/devti/custom/compile/VariableTemplateCompiler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class VariableTemplateCompiler(
2727
private val velocityContext = VelocityContext()
2828

2929
init {
30-
this.set(CustomVariable.SELECTION.variable, selectedText)
30+
this.set(CustomVariable.SELECTION.variable, editor.selectionModel.selectedText ?: selectedText)
3131
this.set(CustomVariable.BEFORE_CURSOR.variable, file.text.substring(0, editor.caretModel.offset))
3232
this.set(CustomVariable.AFTER_CURSOR.variable, file.text.substring(editor.caretModel.offset))
3333
}

src/main/kotlin/cc/unitmesh/devti/gui/chat/AutoDevInputSection.kt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
109109
revalidate()
110110
}
111111

112-
// check new input == $
113-
if (event.newFragment.contentEquals("$") || event.newFragment.contentEquals("¥")) {
112+
if (event.newFragment.contentEquals("$")) {
114113
if (popup == null) {
115114
popup = createPopup()
116115
}
@@ -199,8 +198,9 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
199198
if (selectedItem != null) {
200199
text += "${selectedItem.customVariable.variable} "
201200
}
201+
202+
this@AutoDevInputSection.input.requestFocus()
202203
this@AutoDevInputSection.popup?.cancel()
203-
this@AutoDevInputSection.requestFocus()
204204
}
205205

206206
KeyEvent.VK_DOWN -> {
@@ -221,11 +221,6 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
221221
list.setSelectedIndex(list.getItemsCount() - 1)
222222
}
223223
}
224-
225-
// Esc
226-
KeyEvent.VK_ESCAPE -> {
227-
this@AutoDevInputSection.requestFocus()
228-
}
229224
}
230225
}
231226
})

src/main/kotlin/cc/unitmesh/devti/provider/ContextPrompter.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ import cc.unitmesh.devti.provider.builtin.DefaultContextPrompter
66
import cc.unitmesh.devti.provider.context.ChatContextProvider
77
import cc.unitmesh.devti.provider.context.ChatCreationContext
88
import cc.unitmesh.devti.settings.coder.coderSetting
9-
import com.intellij.lang.html.HTMLLanguage
109
import com.intellij.openapi.diagnostic.logger
1110
import com.intellij.openapi.extensions.ExtensionPointName
1211
import com.intellij.openapi.fileEditor.FileEditorManager
1312
import com.intellij.openapi.project.Project
1413
import com.intellij.openapi.project.ProjectManager
15-
import com.intellij.openapi.vfs.VirtualFile
1614
import com.intellij.psi.PsiDocumentManager
1715
import com.intellij.psi.PsiElement
1816
import com.intellij.psi.PsiFile
@@ -103,7 +101,6 @@ abstract class ContextPrompter : LazyExtensionInstance<ContextPrompter>() {
103101
editor = editor,
104102
selectedText = selectedText
105103
)
106-
107104
}
108105

109106
companion object {

0 commit comments

Comments
 (0)