Skip to content

Commit ea1639b

Browse files
committed
some scrollin
1 parent ec6c13f commit ea1639b

5 files changed

Lines changed: 29 additions & 39 deletions

File tree

ftplugin/TelescopeResults.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Don't have scrolloff, it makes things weird.
2+
vim.opt.scrolloff = 0

lua/telescope/entry_manager.lua

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,6 @@ local log = require "telescope.log"
22

33
local LinkedList = require "telescope.algos.linked_list"
44

5-
--[[
6-
7-
OK, new idea.
8-
We can do linked list here.
9-
To convert at the end to quickfix, just run the list.
10-
...
11-
12-
start node
13-
end node
14-
15-
if past loop of must have scores,
16-
then we can just add to end node and shift end node to current node.
17-
etc.
18-
19-
20-
always inserts a row, because we clear everything before?
21-
22-
can also optimize by keeping worst acceptable score around.
23-
24-
--]]
25-
265
local EntryManager = {}
276
EntryManager.__index = EntryManager
287

lua/telescope/finders/async_job_finder.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local log = require "telescope.log"
77
return function(opts)
88
log.trace("Creating async_job:", opts)
99
local entry_maker = opts.entry_maker or make_entry.gen_from_string()
10+
1011
local fn_command = function(prompt)
1112
local command_list = opts.command_generator(prompt)
1213
if command_list == nil then

lua/telescope/pickers.lua

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ function Picker:is_done()
181181
end
182182
end
183183

184+
-- TODO(scroll)
184185
function Picker:clear_extra_rows(results_bufnr)
185186
if self:is_done() then
186187
log.trace "Not clearing due to being already complete"
@@ -219,21 +220,6 @@ function Picker:clear_extra_rows(results_bufnr)
219220
log.trace("Clearing:", worst_line)
220221
end
221222

222-
function Picker:highlight_displayed_rows(results_bufnr, prompt)
223-
if not self.sorter or not self.sorter.highlighter then
224-
return
225-
end
226-
227-
vim.api.nvim_buf_clear_namespace(results_bufnr, ns_telescope_matching, 0, -1)
228-
229-
local displayed_rows = vim.api.nvim_buf_get_lines(results_bufnr, 0, -1, false)
230-
for row_index = 1, math.min(#displayed_rows, self.max_results) do
231-
local display = displayed_rows[row_index]
232-
233-
self:highlight_one_row(results_bufnr, prompt, display, row_index - 1)
234-
end
235-
end
236-
237223
function Picker:highlight_one_row(results_bufnr, prompt, display, row)
238224
local highlights = self.sorter:highlighter(prompt, display)
239225

@@ -278,6 +264,8 @@ function Picker:_next_find_id()
278264
end
279265

280266
function Picker:find()
267+
self.result_limit = 100000
268+
281269
self:close_existing_pickers()
282270
self:reset_selection()
283271

@@ -353,7 +341,7 @@ function Picker:find()
353341
self:_reset_prefix_color()
354342

355343
-- First thing we want to do is set all the lines to blank.
356-
self.max_results = popup_opts.results.height
344+
self.max_results = 10000 or popup_opts.results.height
357345

358346
-- TODO(scrolling): This may be a hack when we get a little further into implementing scrolling.
359347
vim.api.nvim_buf_set_lines(results_bufnr, 0, self.max_results, false, utils.repeated_table(self.max_results, ""))
@@ -431,6 +419,7 @@ function Picker:find()
431419
self.sorter:_start(prompt)
432420
self.manager = EntryManager:new(self.max_results, self.entry_adder, self.stats)
433421

422+
vim.api.nvim_buf_clear_namespace(results_bufnr, ns_telescope_matching, 0, -1)
434423
local process_result = self:get_result_processor(find_id, prompt, debounced_status)
435424
local process_complete = self:get_result_completor(self.results_bufnr, find_id, prompt, status_updater)
436425

@@ -461,7 +450,6 @@ function Picker:find()
461450
else
462451
-- scheduling required to apply highlighting and selection appropriately
463452
await_schedule(function()
464-
self:highlight_displayed_rows(self.results_bufnr, self.cache_picker.cached_prompt)
465453
if self.cache_picker.selection_row ~= nil then
466454
self:set_selection(self.cache_picker.selection_row)
467455
end
@@ -856,6 +844,8 @@ function Picker:set_selection(row)
856844
self._selection_row = row
857845

858846
self:refresh_previewer()
847+
848+
vim.api.nvim_win_set_cursor(self.results_win, { row + 1, 0 })
859849
end
860850

861851
function Picker:refresh_previewer()
@@ -942,6 +932,7 @@ function Picker:entry_adder(index, entry, _, insert)
942932
local set_ok, msg = pcall(vim.api.nvim_buf_set_lines, self.results_bufnr, row, row + offset, false, { display })
943933
if set_ok and display_highlights then
944934
self.highlighter:hi_display(row, prefix, display_highlights)
935+
self:highlight_one_row(self.results_bufnr, self:_get_prompt(), display, row)
945936
end
946937

947938
if not set_ok then
@@ -1025,9 +1016,17 @@ function Picker:get_status_updater(prompt_win, prompt_bufnr)
10251016
end
10261017

10271018
function Picker:get_result_processor(find_id, prompt, status_updater)
1019+
local stopped = false
1020+
local added = 0
1021+
10281022
local cb_add = function(score, entry)
10291023
self.manager:add_entry(self, score, entry)
10301024
status_updater { completed = false }
1025+
1026+
added = added + 1
1027+
if added > self.result_limit then
1028+
stopped = true
1029+
end
10311030
end
10321031

10331032
local cb_filter = function(_)
@@ -1039,6 +1038,10 @@ function Picker:get_result_processor(find_id, prompt, status_updater)
10391038
return true
10401039
end
10411040

1041+
if stopped then
1042+
return true
1043+
end
1044+
10421045
self:_increment "processed"
10431046

10441047
if not entry or entry.valid == false then
@@ -1075,7 +1078,6 @@ function Picker:get_result_completor(results_bufnr, find_id, prompt, status_upda
10751078
status_updater { completed = true }
10761079

10771080
self:clear_extra_rows(results_bufnr)
1078-
self:highlight_displayed_rows(results_bufnr, prompt)
10791081
self.sorter:_finish(prompt)
10801082

10811083
self:_on_complete()

lua/telescope/pickers/scroller.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ local range_calculators = {
1111
}
1212

1313
local scroll_calculators = {
14+
scroll = function(range_fn)
15+
return function(max_results, num_results, row)
16+
return math.max(row, 0)
17+
end
18+
end,
19+
1420
cycle = function(range_fn)
1521
return function(max_results, num_results, row)
1622
local start, finish = range_fn(max_results, num_results)

0 commit comments

Comments
 (0)