1
1
package cc.unitmesh.devti.gui.chat.ui.file
2
2
3
3
import cc.unitmesh.devti.util.canBeAdded
4
+ import com.intellij.ide.DataManager
4
5
import com.intellij.openapi.fileEditor.impl.EditorHistoryManager
5
6
import com.intellij.openapi.project.Project
6
7
import com.intellij.openapi.project.guessProjectDir
@@ -53,7 +54,7 @@ class WorkspaceFileSearchPopup(
53
54
54
55
private fun loadProjectFiles () {
55
56
allProjectFiles.clear()
56
-
57
+
57
58
// Add recent files with higher priority
58
59
val fileList = EditorHistoryManager .getInstance(project).fileList
59
60
fileList.take(20 ).forEach { file ->
@@ -90,7 +91,7 @@ class WorkspaceFileSearchPopup(
90
91
}
91
92
}
92
93
})
93
-
94
+
94
95
// Configure file list
95
96
fileList.addKeyListener(object : KeyAdapter () {
96
97
override fun keyPressed (e : KeyEvent ) {
@@ -99,10 +100,12 @@ class WorkspaceFileSearchPopup(
99
100
selectFiles()
100
101
e.consume()
101
102
}
103
+
102
104
KeyEvent .VK_ESCAPE -> {
103
105
popup?.cancel()
104
106
e.consume()
105
107
}
108
+
106
109
KeyEvent .VK_UP -> {
107
110
if (fileList.selectedIndex == 0 ) {
108
111
searchField.requestFocus()
@@ -135,20 +138,20 @@ class WorkspaceFileSearchPopup(
135
138
} else {
136
139
allProjectFiles.filter { file ->
137
140
file.name.contains(query, ignoreCase = true ) ||
138
- file.path.contains(query, ignoreCase = true )
141
+ file.path.contains(query, ignoreCase = true )
139
142
}.take(50 )
140
143
}
141
-
144
+
142
145
// Sort files: recent files first, then by name
143
146
val sortedFiles = filteredFiles.sortedWith(compareBy<FilePresentation > { ! it.isRecentFile }.thenBy { it.name })
144
147
sortedFiles.forEach { fileListModel.addElement(it) }
145
-
148
+
146
149
// Auto-select first item if available
147
150
if (fileListModel.size > 0 ) {
148
151
fileList.selectedIndex = 0
149
152
}
150
153
}
151
-
154
+
152
155
private fun selectFiles () {
153
156
val selectedFiles = fileList.selectedValuesList.map { it.virtualFile }
154
157
if (selectedFiles.isNotEmpty()) {
@@ -169,7 +172,7 @@ class WorkspaceFileSearchPopup(
169
172
.setCancelOnOtherWindowOpen(true )
170
173
.setMinSize(minPopupSize)
171
174
.createPopup()
172
-
175
+
173
176
popup?.addListener(object : JBPopupListener {
174
177
override fun onClosed (event : LightweightWindowEvent ) {
175
178
// Clean up resources when popup is closed
@@ -179,9 +182,8 @@ class WorkspaceFileSearchPopup(
179
182
})
180
183
181
184
// Show popup in best position
182
- // popup?.showInBestPositionFor(component)
183
- popup?.showInCenterOf(component)
184
-
185
+ popup?.showInBestPositionFor(DataManager .getInstance().getDataContext(component))
186
+
185
187
// Request focus for search field after popup is shown
186
188
SwingUtilities .invokeLater {
187
189
IdeFocusManager .findInstance().requestFocus(searchField.textEditor, false )
0 commit comments