@@ -46,6 +46,8 @@ import java.awt.Color
46
46
import java.awt.Component
47
47
import java.awt.Dimension
48
48
import java.awt.Point
49
+ import java.awt.event.KeyAdapter
50
+ import java.awt.event.KeyEvent
49
51
import java.awt.event.MouseAdapter
50
52
import java.awt.event.MouseEvent
51
53
import java.util.function.Supplier
@@ -179,22 +181,62 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
179
181
}
180
182
181
183
private fun createPopup (): JBPopup {
182
- val devVariableList = AutoDevVariableList .from(CustomVariable .all()) { item ->
184
+ val list : AutoDevVariableList = AutoDevVariableList .from(CustomVariable .all()) { item ->
183
185
input.text + = item.customVariable.variable
184
186
this .popup?.cancel()
185
187
}
186
188
187
- devVariableList.selectedIndex = 0
189
+ list.selectedIndex = 0
190
+
191
+ list.addKeyListener(object : KeyAdapter () {
192
+ override fun keyPressed (e : KeyEvent ? ) {
193
+ if (! hasPopup()) return
194
+
195
+ when (e?.keyCode) {
196
+ KeyEvent .VK_ENTER -> {
197
+ e.consume()
198
+ val selectedItem = list.getSelectedValue()
199
+ if (selectedItem != null ) {
200
+ text + = " ${selectedItem.customVariable.variable} "
201
+ }
202
+ this @AutoDevInputSection.popup?.cancel()
203
+ }
204
+
205
+ KeyEvent .VK_DOWN -> {
206
+ val selectedIndex = list.selectedIndex
207
+ val itemsCount = list.getItemsCount()
208
+ if (selectedIndex < itemsCount - 1 ) {
209
+ list.setSelectedIndex(selectedIndex + 1 )
210
+ } else {
211
+ list.setSelectedIndex(0 )
212
+ }
213
+ }
214
+
215
+ KeyEvent .VK_UP -> {
216
+ val selectedIndex = list.selectedIndex
217
+ if (selectedIndex > 0 ) {
218
+ list.setSelectedIndex(selectedIndex - 1 )
219
+ } else {
220
+ list.setSelectedIndex(list.getItemsCount() - 1 )
221
+ }
222
+ }
223
+ }
224
+ }
225
+ })
188
226
189
227
val popups = JBPopupFactory .getInstance()
190
- .createComponentPopupBuilder(devVariableList, null )
191
- .setRequestFocus(false )
228
+ .createComponentPopupBuilder(list, null )
229
+ .setFocusable(true )
230
+ .setRequestFocus(true )
192
231
.setMinSize(Dimension (this @AutoDevInputSection.width, 0 ))
193
232
.createPopup()
194
233
195
234
return popups
196
235
}
197
236
237
+ fun hasPopup (): Boolean {
238
+ return popup?.isVisible == true && popup?.isDisposed == false
239
+ }
198
240
199
241
private fun loadRagApps (): List <CustomAgentConfig > {
200
242
val ragsJsonConfig = project.customAgentSetting.ragsJsonConfig
0 commit comments