Skip to content

Commit 63ff29a

Browse files
committed
refactor(WorkspaceFileSearchPopup): improve popup positioning
- Use DataManager for better popup positioning instead of center alignment - Add whitespace formatting for better code readability - Fix indentation in file filtering logic
1 parent d938fe4 commit 63ff29a

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

core/src/main/kotlin/cc/unitmesh/devti/gui/chat/ui/file/WorkspaceFilePanel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class WorkspaceFilePanel(private val project: Project) : JPanel(BorderLayout())
6868
addFileToWorkspace(file)
6969
}
7070
}
71+
7172
popup.show(component)
7273
}
7374

core/src/main/kotlin/cc/unitmesh/devti/gui/chat/ui/file/WorkspaceFileSearchPopup.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cc.unitmesh.devti.gui.chat.ui.file
22

33
import cc.unitmesh.devti.util.canBeAdded
4+
import com.intellij.ide.DataManager
45
import com.intellij.openapi.fileEditor.impl.EditorHistoryManager
56
import com.intellij.openapi.project.Project
67
import com.intellij.openapi.project.guessProjectDir
@@ -53,7 +54,7 @@ class WorkspaceFileSearchPopup(
5354

5455
private fun loadProjectFiles() {
5556
allProjectFiles.clear()
56-
57+
5758
// Add recent files with higher priority
5859
val fileList = EditorHistoryManager.getInstance(project).fileList
5960
fileList.take(20).forEach { file ->
@@ -90,7 +91,7 @@ class WorkspaceFileSearchPopup(
9091
}
9192
}
9293
})
93-
94+
9495
// Configure file list
9596
fileList.addKeyListener(object : KeyAdapter() {
9697
override fun keyPressed(e: KeyEvent) {
@@ -99,10 +100,12 @@ class WorkspaceFileSearchPopup(
99100
selectFiles()
100101
e.consume()
101102
}
103+
102104
KeyEvent.VK_ESCAPE -> {
103105
popup?.cancel()
104106
e.consume()
105107
}
108+
106109
KeyEvent.VK_UP -> {
107110
if (fileList.selectedIndex == 0) {
108111
searchField.requestFocus()
@@ -135,20 +138,20 @@ class WorkspaceFileSearchPopup(
135138
} else {
136139
allProjectFiles.filter { file ->
137140
file.name.contains(query, ignoreCase = true) ||
138-
file.path.contains(query, ignoreCase = true)
141+
file.path.contains(query, ignoreCase = true)
139142
}.take(50)
140143
}
141-
144+
142145
// Sort files: recent files first, then by name
143146
val sortedFiles = filteredFiles.sortedWith(compareBy<FilePresentation> { !it.isRecentFile }.thenBy { it.name })
144147
sortedFiles.forEach { fileListModel.addElement(it) }
145-
148+
146149
// Auto-select first item if available
147150
if (fileListModel.size > 0) {
148151
fileList.selectedIndex = 0
149152
}
150153
}
151-
154+
152155
private fun selectFiles() {
153156
val selectedFiles = fileList.selectedValuesList.map { it.virtualFile }
154157
if (selectedFiles.isNotEmpty()) {
@@ -169,7 +172,7 @@ class WorkspaceFileSearchPopup(
169172
.setCancelOnOtherWindowOpen(true)
170173
.setMinSize(minPopupSize)
171174
.createPopup()
172-
175+
173176
popup?.addListener(object : JBPopupListener {
174177
override fun onClosed(event: LightweightWindowEvent) {
175178
// Clean up resources when popup is closed
@@ -179,9 +182,8 @@ class WorkspaceFileSearchPopup(
179182
})
180183

181184
// Show popup in best position
182-
// popup?.showInBestPositionFor(component)
183-
popup?.showInCenterOf(component)
184-
185+
popup?.showInBestPositionFor(DataManager.getInstance().getDataContext(component))
186+
185187
// Request focus for search field after popup is shown
186188
SwingUtilities.invokeLater {
187189
IdeFocusManager.findInstance().requestFocus(searchField.textEditor, false)

0 commit comments

Comments
 (0)