Skip to content

Commit 58ce17a

Browse files
committed
refactor
1 parent 542f794 commit 58ce17a

File tree

2 files changed

+29
-37
lines changed

2 files changed

+29
-37
lines changed

lua/dired/init.lua

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ int os_get_uname(uv_uid_t uid, char *s, size_t len);
2424

2525
---@class DiredConfig
2626
---@field mark string
27-
---@field enable_fuzzy boolean
2827
---@field show_hidden boolean
2928
---@field prompt_start_insert boolean
3029
---@field prompt_insert_on_open boolean
@@ -35,7 +34,6 @@ local Config = setmetatable({}, {
3534
__index = function(_, scope)
3635
local default = {
3736
show_hidden = true,
38-
enable_fuzzy = true,
3937
prompt_insert_on_open = true,
4038
keymaps = {
4139
open = { i = '<CR>', n = '<CR>' },
@@ -235,6 +233,15 @@ UI.Entry = {
235233
{ ('%-20s '):format(formatted.time), 'DiredDate' },
236234
},
237235
})
236+
if entry.match_pos then
237+
for _, col in ipairs(entry.match_pos[1]) do
238+
api.nvim_buf_set_extmark(state.buf, ns_id, row, col, {
239+
end_col = col + 1,
240+
hl_group = 'Function',
241+
hl_mode = 'combine',
242+
})
243+
end
244+
end
238245
end,
239246
}
240247

@@ -314,8 +321,10 @@ UI.Window = {
314321
local row = api.nvim_win_get_cursor(state.win)[1] - 1
315322
state.count_mark = api.nvim_buf_set_extmark(state.search_buf, ns_id, 0, 0, {
316323
id = state.count_mark or nil,
317-
virt_text = { { ('[%s/%s]'):format(row + 1, #state.entries), 'Comment' } },
318-
virt_text_pos = 'right_align',
324+
virt_text = {
325+
{ ('[%s/%s] Find File: '):format(row + 1, #state.entries), 'DiredTitle' },
326+
},
327+
virt_text_pos = 'inline',
319328
})
320329
end,
321330
})
@@ -615,8 +624,10 @@ Browser.State = {
615624
if api.nvim_buf_is_valid(new_state.search_buf) then
616625
state.count_mark = api.nvim_buf_set_extmark(new_state.search_buf, ns_id, 0, 0, {
617626
id = state.count_mark or nil,
618-
virt_text = { { ('[1/%s]'):format(#entries_to_show), 'Comment' } },
619-
virt_text_pos = 'right_align',
627+
virt_text = {
628+
{ ('[1/%s] Find File: '):format(#entries_to_show), 'DiredTitle' },
629+
},
630+
virt_text_pos = 'inline',
620631
})
621632
end
622633
end)
@@ -627,11 +638,8 @@ Browser.State = {
627638
api.nvim_buf_attach(state.search_buf, false, {
628639
on_lines = function(...)
629640
-- Get search text without prompt path
630-
local text = api
631-
.nvim_get_current_line()
632-
:gsub('Find File: ' .. (state.abbr_path or state.current_path), '')
633-
:gsub('~', vim.env.HOME)
634-
:gsub('^' .. SEPARATOR, '')
641+
local text =
642+
api.nvim_get_current_line():gsub(state.abbr_path or state.current_path, '')
635643

636644
if text == '' or text:match(SEPARATOR .. '$') then
637645
update_display(state, state.entries)
@@ -648,19 +656,15 @@ Browser.State = {
648656
200,
649657
0,
650658
vim.schedule_wrap(function()
651-
local cur = api
652-
.nvim_get_current_line()
653-
:gsub('Find File: ' .. (state.abbr_path or state.current_path), '')
654-
:gsub('~', vim.env.HOME)
655-
:gsub('^' .. SEPARATOR, '')
656-
657-
if cur == text then
659+
if
660+
api.nvim_get_current_line():gsub(state.abbr_path or state.current_path, '')
661+
== text
662+
then
658663
local filtered_entries = {}
659664
for _, entry in ipairs(s.entries) do
660-
if
661-
(Config.enable_fuzzy and #vim.fn.matchfuzzy({ entry.name }, text) > 0)
662-
or entry.name:lower():find(text:lower())
663-
then
665+
local match = vim.fn.matchfuzzypos({ entry.name }, text)
666+
if #match[3] > 0 and match[3][1] > 0 then
667+
entry.match_pos = match[2]
664668
table.insert(filtered_entries, entry)
665669
end
666670
end
@@ -804,7 +808,6 @@ local PathOps = {
804808
getSearchPath = function(state)
805809
local lines = api.nvim_buf_get_lines(state.search_buf, 0, -1, false)
806810
local search_path = lines[#lines]
807-
search_path = search_path:gsub('Find File: ', '')
808811
if vim.startswith(search_path, '~') then
809812
search_path = search_path:gsub('~', vim.env.HOME)
810813
end
@@ -852,21 +855,14 @@ local Actions = {
852855
return F.IO.fromEffect(function()
853856
if api.nvim_buf_is_valid(refreshed_state.search_buf) then
854857
path = refreshed_state.abbr_path or refreshed_state.current_path
855-
api.nvim_buf_set_lines(
856-
refreshed_state.search_buf,
857-
0,
858-
-1,
859-
false,
860-
{ 'Find File: ' .. path }
861-
)
862-
local end_col = api.nvim_strwidth(path) + 11
858+
api.nvim_buf_set_lines(refreshed_state.search_buf, 0, -1, false, { path })
859+
local end_col = api.nvim_strwidth(path)
863860
api.nvim_win_set_cursor(refreshed_state.search_win, { 1, end_col })
864-
api.nvim_buf_set_extmark(refreshed_state.search_buf, ns_id, 0, 11, {
861+
api.nvim_buf_set_extmark(refreshed_state.search_buf, ns_id, 0, 0, {
865862
end_col = end_col,
866863
hl_group = 'DiredPrompt',
867864
})
868865
api.nvim_buf_set_extmark(refreshed_state.search_buf, ns_id, 0, 0, {
869-
end_col = 10,
870866
hl_group = 'DiredTitle',
871867
hl_mode = 'combine',
872868
})

plugin/dired.lua

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ local highlights = {
1717
DiredSize = { fg = '#8fbcbb' },
1818
DiredUser = { fg = '#d08770' },
1919
DiredDate = { fg = '#4c566a' },
20-
DiredHeader = { fg = '#81a1c1', bold = true },
21-
DiredHeaderLine = { fg = '#3b4252' },
22-
DiredCurrent = { bg = '#41466e' },
2320
DiredPrompt = { fg = '#a3be8c' },
24-
DiredMark = { fg = '#d66363' },
2521
DiredTitle = { link = 'Function' },
2622
}
2723

0 commit comments

Comments
 (0)