Skip to content

Commit a53be1e

Browse files
author
a.iudin
committed
Remove unused lookup aggregation; add delete/backspace handling and click-to-edit
Eliminate allAvailableItems property and allGroupItemsJob Remove handleSuggestionSelection function Add delete/backspace key handling to refresh group lookup Enable search field text editor to become editable on mouse click
1 parent 3c276af commit a53be1e

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

src/main/kotlin/ee/carlrobert/codegpt/ui/textarea/PromptTextField.kt

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class PromptTextField(
6969
private var currentPopup: JBPopup? = null
7070
private var currentParentGroup: LookupGroupItem? = null
7171
private var currentItems: List<LookupItem> = emptyList()
72-
private var allAvailableItems: List<LookupItem> = emptyList()
7372

7473
init {
7574
isOneLineMode = false
@@ -111,21 +110,6 @@ class PromptTextField(
111110
withContext(Dispatchers.EDT) {
112111
editor?.let { showPopupLookup(it, lookupItems) }
113112
}
114-
115-
allGroupItemsJob?.cancel()
116-
allGroupItemsJob = coroutineScope.launch {
117-
val allItems = mutableListOf<LookupItem>()
118-
lookupItems.forEach { group ->
119-
if (group is LookupGroupItem) {
120-
runCatchingCancellable {
121-
allItems.addAll(group.getLookupItems())
122-
}
123-
} else {
124-
allItems.add(group)
125-
}
126-
}
127-
allAvailableItems = allItems
128-
}
129113
}
130114

131115
private fun showPopupLookup(editor: Editor, items: List<LookupItem>) {
@@ -210,6 +194,16 @@ class PromptTextField(
210194
e.consume()
211195
}
212196

197+
KeyEvent.VK_DELETE, KeyEvent.VK_BACK_SPACE -> {
198+
if (parentGroup != null) {
199+
showSuggestionsJob?.cancel()
200+
showSuggestionsJob = coroutineScope.launch {
201+
showGroupLookup()
202+
}
203+
e.consume()
204+
}
205+
}
206+
213207
else -> {
214208
if (e.keyChar.isLetterOrDigit() || e.keyChar.isWhitespace()) {
215209
searchField.textEditor.isEditable = true
@@ -240,6 +234,16 @@ class PromptTextField(
240234
searchField.apply {
241235
textEditor.isEditable = false
242236

237+
textEditor.addMouseListener(object : MouseAdapter() {
238+
override fun mouseClicked(e: MouseEvent) {
239+
textEditor.isEditable = true
240+
textEditor.requestFocusInWindow()
241+
val text = textEditor.text
242+
textEditor.caretPosition = text.length
243+
textEditor.caret.isVisible = true
244+
}
245+
})
246+
243247
textEditor.addKeyListener(object : KeyAdapter() {
244248
override fun keyPressed(e: KeyEvent) {
245249
when (e.keyCode) {
@@ -459,13 +463,6 @@ class PromptTextField(
459463
}
460464
}
461465

462-
private fun handleSuggestionSelection(editor: Editor, item: LookupItem) {
463-
if (item !is LookupActionItem) return
464-
465-
replaceAtSymbol(editor, item)
466-
onLookupAdded(item)
467-
}
468-
469466
private fun replaceAtSymbol(editor: Editor, lookupItem: LookupItem) {
470467
val offset = editor.caretModel.offset
471468
val start = findAtSymbolPosition(editor)
@@ -509,7 +506,6 @@ class PromptTextField(
509506
override fun dispose() {
510507
searchJob?.cancel()
511508
showSuggestionsJob?.cancel()
512-
allGroupItemsJob?.cancel()
513509
currentPopup?.cancel()
514510
}
515511

0 commit comments

Comments
 (0)