Skip to content

Commit

Permalink
fix(gui): only trigger popup on '$' input #51
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
phodal committed Mar 6, 2024
1 parent 93a5e52 commit 4535dc8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
Expand Up @@ -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))
}
Expand Down
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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 -> {
Expand All @@ -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()
}
}
}
})
Expand Down
3 changes: 0 additions & 3 deletions src/main/kotlin/cc/unitmesh/devti/provider/ContextPrompter.kt
Expand Up @@ -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
Expand Down Expand Up @@ -103,7 +101,6 @@ abstract class ContextPrompter : LazyExtensionInstance<ContextPrompter>() {
editor = editor,
selectedText = selectedText
)

}

companion object {
Expand Down

0 comments on commit 4535dc8

Please sign in to comment.