Skip to content

Commit aaa96a4

Browse files
committed
fuck
1 parent e20aeed commit aaa96a4

File tree

1 file changed

+66
-61
lines changed

1 file changed

+66
-61
lines changed

lua/dired/init.lua

Lines changed: 66 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,9 @@ UI.Window = {
299299
'',
300300
'',
301301
},
302+
style = 'minimal',
302303
})
303304

304-
vim.wo[win].wrap = false
305-
vim.wo[win].number = false
306-
vim.wo[win].relativenumber = false
307-
vim.wo[win].stc = ''
308-
vim.wo[win].signcolumn = 'no'
309305
vim.wo[win].fillchars = 'eob: '
310306
vim.wo[win].list = false
311307
-- Enter insert mode in prompt buffer
@@ -654,12 +650,16 @@ local function create_shortcut_manager()
654650
return { top, bot }
655651
end)
656652

653+
local new = {}
657654
for key, lnum in pairs(assigned) do
658655
if lnum < visible[1] or lnum > visible[2] then
659656
vim.keymap.del('n', key, { buffer = state.search_buf })
660657
table.insert(pool, key)
658+
else
659+
new[key] = lnum
661660
end
662661
end
662+
assigned = new
663663
end,
664664
}
665665
end
@@ -682,6 +682,7 @@ Browser.State = {
682682
s.original_entries = {}
683683
s.clipboard = {}
684684
s.shortcut_manager = create_shortcut_manager()
685+
s.initialized = false
685686

686687
-- Function to update display with entries
687688
local function update_display(new_state, entries_to_show)
@@ -701,7 +702,11 @@ Browser.State = {
701702
new_state.shortcut_manager.assign(new_state, i - 1)
702703
end
703704

704-
if #entries_to_show <= api.nvim_win_get_height(new_state.win) then
705+
local mode = api.nvim_get_mode().mode
706+
if
707+
not s.initialized
708+
and #entries_to_show <= api.nvim_win_get_height(new_state.win)
709+
then
705710
api.nvim_feedkeys(api.nvim_replace_termcodes('<ESC>', true, false, true), 'n', true)
706711
end
707712

@@ -714,61 +719,64 @@ Browser.State = {
714719
virt_text_pos = 'inline',
715720
})
716721
end
717-
end)
718-
end
719-
720-
local timer = assert(vim.uv.new_timer())
721-
-- Attach buffer for search
722-
api.nvim_buf_attach(state.search_buf, false, {
723-
on_lines = function(...)
724-
-- Get search text without prompt path
725-
local text =
726-
api.nvim_get_current_line():gsub(state.abbr_path or state.current_path, '')
727-
728-
if text == '' or text:match(SEPARATOR .. '$') then
729-
update_display(state, state.entries)
730-
return
731-
end
722+
if not s.initialized then
723+
local timer = assert(vim.uv.new_timer())
724+
-- Attach buffer for search
725+
api.nvim_buf_attach(state.search_buf, false, {
726+
on_lines = function(...)
727+
-- Get search text without prompt path
728+
local text =
729+
api.nvim_get_current_line():gsub(state.abbr_path or state.current_path, '')
730+
731+
if text == '' or text:match(SEPARATOR .. '$') then
732+
update_display(state, state.entries)
733+
return
734+
end
732735

733-
-- Clear previous timer if exists
734-
if timer:is_active() then
735-
timer:stop()
736-
end
736+
-- Clear previous timer if exists
737+
if timer:is_active() then
738+
timer:stop()
739+
end
737740

738-
-- Set new timer for delayed search
739-
timer:start(
740-
200,
741-
0,
742-
vim.schedule_wrap(function()
743-
if
744-
api.nvim_get_current_line():gsub(state.abbr_path or state.current_path, '')
745-
== text
746-
then
747-
local filtered_entries = {}
748-
for _, entry in ipairs(s.entries) do
749-
local match = vim.fn.matchfuzzypos({ entry.name }, text)
750-
if #match[3] > 0 and match[3][1] > 0 then
751-
entry.match_pos = match[2][1]
752-
entry.score = match[3][1]
753-
table.insert(filtered_entries, entry)
754-
end
741+
-- Set new timer for delayed search
742+
timer:start(
743+
200,
744+
0,
745+
vim.schedule_wrap(function()
746+
if
747+
api
748+
.nvim_get_current_line()
749+
:gsub(state.abbr_path or state.current_path, '')
750+
== text
751+
then
752+
local filtered_entries = {}
753+
for _, entry in ipairs(s.entries) do
754+
local match = vim.fn.matchfuzzypos({ entry.name }, text)
755+
if #match[3] > 0 and match[3][1] > 0 then
756+
entry.match_pos = match[2][1]
757+
entry.score = match[3][1]
758+
table.insert(filtered_entries, entry)
759+
end
760+
end
761+
table.sort(filtered_entries, function(a, b)
762+
return a.score > b.score
763+
end)
764+
update_display(state, filtered_entries)
765+
end
766+
end)
767+
)
768+
end,
769+
on_detach = function()
770+
if timer:is_active() then
771+
timer:stop()
755772
end
756-
table.sort(filtered_entries, function(a, b)
757-
return a.score > b.score
758-
end)
759-
update_display(state, filtered_entries)
760-
end
761-
end)
762-
)
763-
end,
764-
on_detach = function()
765-
-- Clean up timer when buffer is closed
766-
if timer:is_active() then
767-
timer:stop()
773+
timer:close()
774+
end,
775+
})
768776
end
769-
timer:close()
770-
end,
771-
})
777+
s.initialized = true
778+
end)
779+
end
772780

773781
-- Add the update_display function to state for later use
774782
s.update_display = update_display
@@ -1393,10 +1401,7 @@ Browser.executeOperations = function(state, operations)
13931401
end
13941402

13951403
local function browse_directory(path)
1396-
if not path:find(SEPARATOR .. '$') then
1397-
path = path .. SEPARATOR
1398-
end
1399-
1404+
path = path:find(SEPARATOR .. '$') and path or path .. SEPARATOR
14001405
F.IO
14011406
.chain(Browser.State.create(path), function(state)
14021407
return F.IO.chain(Browser.setup(state), function(s)

0 commit comments

Comments
 (0)