Skip to content

Commit

Permalink
[WIP]: Fri 10 Sep 2021 02:24:20 PM EDT
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdevries committed Sep 10, 2021
1 parent 8774077 commit dc58243
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 38 deletions.
87 changes: 50 additions & 37 deletions lua/telescope/pickers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ function Picker:clear_extra_rows(results_bufnr)
end

function Picker:highlight_one_row(results_bufnr, prompt, display, row)
if not self.sorter.highlighter then
return
end

local highlights = self.sorter:highlighter(prompt, display)

if highlights then
Expand Down Expand Up @@ -355,7 +359,7 @@ function Picker:find()
local debounced_status = debounce.throttle_leading(status_updater, 50)

local tx, rx = channel.mpsc()
self.__on_lines = tx.send
self._on_lines = tx.send

local find_id = self:_next_find_id()

Expand Down Expand Up @@ -400,19 +404,7 @@ function Picker:find()

local start_time = vim.loop.hrtime()

local prompt = self:_get_prompt()
local on_input_result = self._on_input_filter_cb(prompt) or {}

local new_prompt = on_input_result.prompt
if new_prompt then
prompt = new_prompt
end

local new_finder = on_input_result.updated_finder
if new_finder then
self.finder:close()
self.finder = new_finder
end
local prompt = self:_get_next_filtered_prompt()

-- TODO: Entry manager should have a "bulk" setter. This can prevent a lot of redraws from display
if self.cache_picker == false or not (self.cache_picker.is_cached == true) then
Expand All @@ -436,25 +428,8 @@ function Picker:find()
async.util.sleep(self.debounce - diff_time)
end
else
-- resume previous picker
local index = 1
for entry in self.manager:iter() do
self:entry_adder(index, entry, _, true)
index = index + 1
end
self.cache_picker.is_cached = false
-- if text changed, required to set anew to restart finder; otherwise hl and selection
if self.cache_picker.cached_prompt ~= self.default_text then
self:reset_prompt()
self:set_prompt(self.default_text)
else
-- scheduling required to apply highlighting and selection appropriately
await_schedule(function()
if self.cache_picker.selection_row ~= nil then
self:set_selection(self.cache_picker.selection_row)
end
end)
end
-- TODO(scroll): This can only happen once, I don't like where it is.
self:_resume_picker()
end
end
end)
Expand All @@ -464,10 +439,10 @@ function Picker:find()
on_lines = function(...)
find_id = self:_next_find_id()

self._result_completed = false
status_updater { completed = false }
tx.send(...)
end,

on_detach = function()
self:_detach()
end,
Expand Down Expand Up @@ -741,7 +716,7 @@ function Picker:refresh(finder, opts)
self._multi = MultiSelect:new()
end

self.__on_lines(nil, nil, nil, 0, 1)
self._on_lines(nil, nil, nil, 0, 1)
end

function Picker:set_selection(row)
Expand Down Expand Up @@ -1081,8 +1056,6 @@ function Picker:get_result_completor(results_bufnr, find_id, prompt, status_upda
self.sorter:_finish(prompt)

self:_on_complete()

self._result_completed = true
end)
end

Expand Down Expand Up @@ -1228,6 +1201,46 @@ function Picker:_detach()
self.closed = true
end

function Picker:_get_next_filtered_prompt()
local prompt = self:_get_prompt()
local on_input_result = self._on_input_filter_cb(prompt) or {}

local new_prompt = on_input_result.prompt
if new_prompt then
prompt = new_prompt
end

local new_finder = on_input_result.updated_finder
if new_finder then
self.finder:close()
self.finder = new_finder
end

return prompt
end

function Picker:_resume_picker()
-- resume previous picker
local index = 1
for entry in self.manager:iter() do
self:entry_adder(index, entry, _, true)
index = index + 1
end
self.cache_picker.is_cached = false
-- if text changed, required to set anew to restart finder; otherwise hl and selection
if self.cache_picker.cached_prompt ~= self.default_text then
self:reset_prompt()
self:set_prompt(self.default_text)
else
-- scheduling required to apply highlighting and selection appropriately
await_schedule(function()
if self.cache_picker.selection_row ~= nil then
self:set_selection(self.cache_picker.selection_row)
end
end)
end
end

pickers._Picker = Picker

return pickers
2 changes: 1 addition & 1 deletion lua/telescope/pickers/scroller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local range_calculators = {
local scroll_calculators = {
scroll = function(range_fn)
return function(max_results, num_results, row)
return math.max(row, 0)
return math.min(math.max(row, 0), max_results - 1)
end
end,

Expand Down

0 comments on commit dc58243

Please sign in to comment.