Skip to content

Commit 4900655

Browse files
ipttonphodal
authored andcommitted
feat(quick-assistant): add ESC handler for inlay panel && dismiss previous inlay panel when new one shown
Handle ESC key to dispose inlay panel and cleanup resources. Track current panel instance for proper disposal close #375
1 parent 4967507 commit 4900655

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

core/src/main/kotlin/cc/unitmesh/devti/actions/quick/QuickAssistantAction.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.intellij.openapi.wm.IdeFocusManager
2525
import com.intellij.psi.PsiElement
2626
import com.intellij.psi.PsiFile
2727
import cc.unitmesh.devti.inlay.InlayPanel
28+
import cc.unitmesh.devti.inline.EscHandler
2829
import java.awt.event.ActionEvent
2930
import javax.swing.AbstractAction
3031

@@ -33,6 +34,10 @@ import javax.swing.AbstractAction
3334
* user can input custom text to call with LLM.
3435
*/
3536
open class QuickAssistantAction : AnAction() {
37+
38+
private var currentInlayPanel: InlayPanel<QuickPromptField>? = null
39+
private var escHandler: EscHandler? = null
40+
3641
init{
3742
presentationText("settings.autodev.others.quickAssistant", templatePresentation)
3843
}
@@ -101,7 +106,15 @@ open class QuickAssistantAction : AnAction() {
101106
}
102107

103108
private fun useInlayMode(editor: Editor, offset: Int, project: Project, element: PsiElement?) {
104-
InlayPanel.add(editor as EditorEx, offset, QuickPromptField())?.let {
109+
currentInlayPanel?.let {
110+
Disposer.dispose(it.inlay!!)
111+
}
112+
escHandler = EscHandler(editor) {
113+
Disposer.dispose(currentInlayPanel?.inlay!!)
114+
escHandler?.dispose()
115+
}
116+
currentInlayPanel = InlayPanel.add(editor as EditorEx, offset, QuickPromptField())?.also {
117+
currentInlayPanel = null
105118
doExecute(it, project, editor, element)
106119
}
107120
}

0 commit comments

Comments
 (0)