Skip to content

Commit e2555ac

Browse files
committed
update
1 parent 545e82e commit e2555ac

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

lua/dired/init.lua

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ local function create_debounced_search()
763763
local current_job = nil
764764
local pending_search = nil
765765
local search_id = 0
766-
local handled_results = 0
766+
local handled_results = {}
767767

768768
local function cleanup()
769769
if timer then
@@ -782,7 +782,7 @@ local function create_debounced_search()
782782
local reset = function()
783783
last_search = ''
784784
is_searching = false
785-
handled_results = 0
785+
handled_results = {}
786786
search_id = search_id + 1
787787
cleanup()
788788
end
@@ -793,25 +793,25 @@ local function create_debounced_search()
793793
end
794794

795795
local filters = {}
796-
if #results > 0 then
797-
local names = Iter(results):map(function(entry)
798-
return entry.name
799-
end):totable()
800-
local res = vim.fn.matchfuzzypos(names, search_text)
801-
for _, entry in ipairs(results) do
802-
for k, v in ipairs(res[1]) do
803-
if v == entry.name then
804-
entry.match_pos = res[2][k]
805-
entry.score = res[3][k] or 0
806-
table.insert(filters, entry)
807-
end
796+
local names = Iter(results):map(function(entry)
797+
return entry.name
798+
end):totable()
799+
local res = vim.fn.matchfuzzypos(names, search_text)
800+
for _, entry in ipairs(results) do
801+
for k, v in ipairs(res[1]) do
802+
if v == entry.name then
803+
entry.match_pos = res[2][k]
804+
entry.score = res[3][k] or 0
805+
table.insert(filters, entry)
808806
end
809807
end
810-
table.sort(filters, function(a, b)
811-
return a.score > b.score
812-
end)
813808
end
814-
callback(filters, handled_results)
809+
810+
handled_results = vim.list_extend(handled_results, filters)
811+
table.sort(handled_results, function(a, b)
812+
return a.score > b.score
813+
end)
814+
callback(vim.list_slice(handled_results, 1, 80), #handled_results)
815815
end
816816

817817
local function execute_search(state, search_text, callback)
@@ -855,7 +855,6 @@ local function create_debounced_search()
855855
end
856856

857857
if current_search_id == search_id and #results > 0 then
858-
handled_results = handled_results + #results
859858
vim.schedule(function()
860859
process_and_display_results(results, search_text, callback, current_search_id)
861860
end)
@@ -912,15 +911,17 @@ Browser.State = {
912911
s.initialized = false
913912

914913
-- Function to update display with entries
915-
local function update_display(new_state, entries_to_show, change_mode)
914+
local function update_display(new_state, entries_to_show, change_mode, append)
916915
vim.schedule(function()
917916
if next(s.shortcut_manager.get()) ~= nil then
918917
s.shortcut_manager.reset(new_state)
919918
end
920919

921920
if api.nvim_buf_is_valid(new_state.buf) then
922-
api.nvim_buf_set_lines(new_state.buf, 0, -1, false, {})
923-
api.nvim_buf_clear_namespace(new_state.buf, ns_id, 0, -1)
921+
if not append then
922+
api.nvim_buf_set_lines(new_state.buf, 0, -1, false, {})
923+
api.nvim_buf_clear_namespace(new_state.buf, ns_id, 0, -1)
924+
end
924925

925926
state.count_mark = api.nvim_buf_set_extmark(new_state.search_buf, ns_id, 0, 0, {
926927
id = state.count_mark or nil,
@@ -943,11 +944,14 @@ Browser.State = {
943944
vim.bo[new_state.buf].modifiable = true
944945
for i, entry in ipairs(entries_to_show) do
945946
UI.Entry.render(new_state, i - 1, entry)
947+
-- no need render more than window height
948+
if i + 1 > 80 then
949+
break
950+
end
946951
end
947952
end
948953

949-
local win_height = api.nvim_win_get_height(new_state.win)
950-
local visible_end = math.min(#entries_to_show, win_height)
954+
local visible_end = api.nvim_buf_line_count(new_state.buf)
951955
for i = 1, visible_end do
952956
new_state.shortcut_manager.assign(new_state, i - 1)
953957
end
@@ -991,7 +995,7 @@ Browser.State = {
991995
})
992996
return
993997
end
994-
update_display(state, entries)
998+
update_display(state, entries, false, true)
995999
end, 50)
9961000
end,
9971001
on_detach = function()

0 commit comments

Comments
 (0)