Skip to content

Commit 55a439e

Browse files
committed
update
1 parent c7b99a5 commit 55a439e

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

lua/dired/init.lua

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,22 @@ UI.Window = {
433433
end,
434434
}
435435

436+
UI.Prompt = {
437+
-- Set prompt text with proper highlighting
438+
set = function(state)
439+
return F.IO.fromEffect(function()
440+
vim.fn.prompt_setprompt(state.search_buf, state.current_path)
441+
local prompt_lnum = api.nvim_buf_line_count(state.search_buf)
442+
local line = api.nvim_get_current_line()
443+
prompt_lnum = (prompt_lnum == 1 and #line == 0) and 0 or prompt_lnum
444+
api.nvim_buf_set_extmark(state.search_buf, ns_id, prompt_lnum, 0, {
445+
line_hl_group = 'DiredPrompt',
446+
})
447+
return state
448+
end)
449+
end,
450+
}
451+
436452
-- Browser implementation
437453
local Browser = {}
438454

@@ -788,6 +804,7 @@ local Actions = {
788804
openDirectory = function(state, path)
789805
Browser.refresh(state, path).run()
790806
state.current_path = path
807+
UI.Prompt.set(state).run()
791808
if api.nvim_get_mode().mode ~= 'i' and Config.prompt_insert_on_open then
792809
vim.cmd.startinsert()
793810
end
@@ -1013,11 +1030,7 @@ Browser.setup = function(state)
10131030
local search_path = PathOps.getSearchPath(state) .. SEPARATOR
10141031
if PathOps.isDirectory(search_path) then
10151032
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-
})
1033+
UI.Prompt.set(state).run()
10211034
return Browser.refresh(state, state.current_path).run()
10221035
end
10231036
end,
@@ -1100,7 +1113,7 @@ Browser.setup = function(state)
11001113
state.current_path = vim.fs.dirname(state.current_path:gsub(SEPARATOR .. '$', ''))
11011114
.. SEPARATOR
11021115
Browser.refresh(state, state.current_path).run()
1103-
vim.fn.prompt_setprompt(state.search_buf, state.current_path)
1116+
UI.Prompt.set(state).run()
11041117
return '<NL>'
11051118
end
11061119
return '<BS>'
@@ -1167,11 +1180,7 @@ Browser.refresh = function(state, path)
11671180
if #tasks == 0 then
11681181
vim.schedule(function()
11691182
updateBuffer({})
1170-
vim.fn.prompt_setprompt(state.search_buf, state.current_path)
1171-
local count = api.nvim_buf_line_count(state.search_buf)
1172-
api.nvim_buf_set_extmark(state.search_buf, ns_id, count, 0, {
1173-
line_hl_group = 'DiredPrompt',
1174-
})
1183+
UI.Prompt.set(state).run()
11751184
end)
11761185
return state
11771186
end
@@ -1255,11 +1264,9 @@ local function browse_directory(path)
12551264
F.IO
12561265
.chain(Browser.State.create(path), function(state)
12571266
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-
})
1262-
return Browser.refresh(s, path)
1267+
return F.IO.chain(UI.Prompt.set(s), function()
1268+
return Browser.refresh(s, path)
1269+
end)
12631270
end)
12641271
end)
12651272
.run()

0 commit comments

Comments
 (0)