@@ -500,11 +500,14 @@ Browser.State = {
500500 local timer = assert (vim .uv .new_timer ())
501501 -- Attach buffer for search
502502 api .nvim_buf_attach (s .search_buf , false , {
503- on_lines = function ()
503+ on_lines = function (... )
504504 -- Get search text without prompt path
505505 local text =
506506 api .nvim_get_current_line ():gsub (s .current_path , ' ' ):gsub (' ^' .. SEPARATOR , ' ' )
507507
508+ if text == ' ' or text :match (SEPARATOR .. ' $' ) then
509+ return
510+ end
508511 -- Clear previous timer if exists
509512 if timer :is_active () then
510513 timer :stop ()
@@ -515,10 +518,9 @@ Browser.State = {
515518 200 ,
516519 0 ,
517520 vim .schedule_wrap (function ()
518- if text :match (SEPARATOR .. ' $' ) then
519- return
520- end
521- if text and # text > 0 then
521+ local cur =
522+ api .nvim_get_current_line ():gsub (s .current_path , ' ' ):gsub (' ^' .. SEPARATOR , ' ' )
523+ if cur == text then
522524 local filtered_entries = {}
523525 for _ , entry in ipairs (s .entries ) do
524526 if
@@ -529,8 +531,6 @@ Browser.State = {
529531 end
530532 end
531533 update_display (s , filtered_entries )
532- else
533- Browser .refresh (s , s .current_path ).run ()
534534 end
535535 end )
536536 )
@@ -1013,14 +1013,13 @@ Browser.setup = function(state)
10131013 local search_path = PathOps .getSearchPath (state ) .. SEPARATOR
10141014 if PathOps .isDirectory (search_path ) then
10151015 state .current_path = search_path
1016+ local lnum = api .nvim_win_get_cursor (state .search_win )[1 ]
1017+ vim .fn .prompt_setprompt (state .search_buf , search_path )
1018+ api .nvim_buf_set_extmark (state .search_buf , ns_id , lnum , 0 , {
1019+ line_hl_group = ' DiredPrompt' ,
1020+ })
10161021 return Browser .refresh (state , state .current_path ).run ()
10171022 end
1018-
1019- local lnum = api .nvim_win_get_cursor (state .search_win )[1 ]
1020- vim .fn .prompt_setprompt (state .search_buf , search_path )
1021- api .nvim_buf_set_extmark (state .search_buf , ns_id , lnum , 0 , {
1022- line_hl_group = ' DiredPrompt' ,
1023- })
10241023 end ,
10251024 },
10261025 {
@@ -1215,17 +1214,12 @@ Browser.refresh = function(state, path)
12151214 end
12161215
12171216 local pos = api .nvim_win_get_cursor (state .search_win )
1218- local prompt_lnum = pos [1 ] - 1
12191217 -- Execute all updates
12201218 local formatted_entries , max_width = formatEntries ()
12211219 local cfg = api .nvim_win_get_config (state .win )
12221220 cfg .width = max_width
12231221 local new_col = math.floor ((vim .o .columns - max_width ) / 2 )
12241222 cfg .col = new_col
1225- -- when first open set prompt line number to 0
1226- if cfg .hide then
1227- prompt_lnum = 0
1228- end
12291223 cfg .hide = false
12301224 api .nvim_win_set_config (state .win , cfg )
12311225
@@ -1241,10 +1235,6 @@ Browser.refresh = function(state, path)
12411235 api .nvim_win_set_cursor (state .win , { 3 , 1 })
12421236 Browser .update_current_hl (state , 2 )
12431237
1244- vim .fn .prompt_setprompt (state .search_buf , state .current_path )
1245- api .nvim_buf_set_extmark (state .search_buf , ns_id , prompt_lnum , 0 , {
1246- line_hl_group = ' DiredPrompt' ,
1247- })
12481238 -- Update state
12491239 state .entries = collected_entries
12501240 end )
@@ -1265,6 +1255,10 @@ local function browse_directory(path)
12651255 F .IO
12661256 .chain (Browser .State .create (path ), function (state )
12671257 return F .IO .chain (Browser .setup (state ), function (s )
1258+ vim .fn .prompt_setprompt (state .search_buf , state .current_path )
1259+ api .nvim_buf_set_extmark (state .search_buf , ns_id , 0 , 0 , {
1260+ line_hl_group = ' DiredPrompt' ,
1261+ })
12681262 return Browser .refresh (s , path )
12691263 end )
12701264 end )
0 commit comments