@@ -183,6 +183,8 @@ class ExTextField internal constructor(private val myParentPanel: ExEntryPanel)
183183 document.setSpecialKeyForeground(fg)
184184 }
185185 }
186+ private var completionModePrefix: String = " "
187+ private var completionModeEnabled: Boolean = false
186188
187189 /* *
188190 * Finish handling the keystroke
@@ -205,8 +207,11 @@ class ExTextField internal constructor(private val myParentPanel: ExEntryPanel)
205207 // what it will do with the keystroke)
206208 if (stroke.keyChar != KeyEvent .CHAR_UNDEFINED ) {
207209 replaceSelection(stroke.keyChar.toString())
208- } else {
210+ completionModeEnabled = false
211+ }
212+ else {
209213 if (stroke.keyCode != KeyEvent .VK_TAB || ! executeTabCompletionIfPossible()) {
214+ completionModeEnabled = false
210215 val event = KeyEvent (
211216 this , stroke.keyEventType, (Date ()).time, stroke.modifiers,
212217 stroke.keyCode, stroke.keyChar
@@ -247,6 +252,7 @@ class ExTextField internal constructor(private val myParentPanel: ExEntryPanel)
247252 )
248253 e.consume()
249254 } else {
255+ completionModeEnabled = false
250256 super .processKeyEvent(e)
251257 }
252258 }
@@ -263,20 +269,19 @@ class ExTextField internal constructor(private val myParentPanel: ExEntryPanel)
263269 val projectBasePath = project?.basePath?.let { Path .of(it) } ? : return false
264270 val inputPath = projectBasePath.resolve(input)
265271 val inputPathString = inputPath.toString()
272+ val searchPrefix = if (completionModeEnabled) completionModePrefix else inputPathString
266273
267274 // Would it be useful to ignore file path case?
268275 try {
269276 val filePaths = (
270277 if (inputPath.exists()) {
271- if (inputPath.isDirectory())
278+ if (inputPath.isDirectory() && ! completionModeEnabled )
272279 Files .list(inputPath)
273280 else
274281 Files .list(inputPath.parent)
275282 } else if (inputPath.isAbsolute || inputPath.exists()) Files .list(inputPath.parent)
276- .filter { it.toString().startsWith(inputPathString) }
277283 else Files .list(projectBasePath)
278- .filter { it.toString().startsWith(inputPathString) }
279- ).sorted().toList()
284+ ).filter { it.toString().startsWith(searchPrefix) }.sorted().toList()
280285
281286 if (filePaths.isEmpty()) return false
282287
@@ -290,6 +295,10 @@ class ExTextField internal constructor(private val myParentPanel: ExEntryPanel)
290295 val isDir = suggestion.isDirectory()
291296 val effectivePath = if (projectBasePath > suggestion) suggestion else projectBasePath.relativize(suggestion)
292297 updateText(String .format(" %s %s%s" , command, effectivePath, if (isDir) " /" else " " ))
298+ if (! completionModeEnabled) {
299+ completionModeEnabled = true
300+ completionModePrefix = inputPathString
301+ }
293302 return true
294303 } catch (e: IOException ) {
295304 logger.error(e)
0 commit comments