fix: No longer lose highlights when moving through results
This commit is contained in:
@@ -227,7 +227,6 @@ function Picker:clear_extra_rows(results_bufnr)
|
|||||||
if self.sorting_strategy == 'ascending' then
|
if self.sorting_strategy == 'ascending' then
|
||||||
local num_results = self.manager:num_results()
|
local num_results = self.manager:num_results()
|
||||||
local worst_line = self.max_results - num_results
|
local worst_line = self.max_results - num_results
|
||||||
log.info(self.max_results, num_results, worst_line)
|
|
||||||
|
|
||||||
if worst_line <= 0 then
|
if worst_line <= 0 then
|
||||||
return
|
return
|
||||||
@@ -253,9 +252,14 @@ function Picker:highlight_displayed_rows(results_bufnr, prompt)
|
|||||||
vim.api.nvim_buf_clear_namespace(results_bufnr, ns_telescope_matching, 0, -1)
|
vim.api.nvim_buf_clear_namespace(results_bufnr, ns_telescope_matching, 0, -1)
|
||||||
|
|
||||||
local displayed_rows = vim.api.nvim_buf_get_lines(results_bufnr, 0, -1, false)
|
local displayed_rows = vim.api.nvim_buf_get_lines(results_bufnr, 0, -1, false)
|
||||||
for row = 1, #displayed_rows do
|
for row_index = 1, #displayed_rows do
|
||||||
local display = displayed_rows[row]
|
local display = displayed_rows[row_index]
|
||||||
|
|
||||||
|
self:highlight_one_row(results_bufnr, prompt, display, row_index - 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Picker:highlight_one_row(results_bufnr, prompt, display, row)
|
||||||
local highlights = self.sorter:highlighter(prompt, display)
|
local highlights = self.sorter:highlighter(prompt, display)
|
||||||
if highlights then
|
if highlights then
|
||||||
for _, hl in ipairs(highlights) do
|
for _, hl in ipairs(highlights) do
|
||||||
@@ -276,13 +280,12 @@ function Picker:highlight_displayed_rows(results_bufnr, prompt)
|
|||||||
results_bufnr,
|
results_bufnr,
|
||||||
ns_telescope_matching,
|
ns_telescope_matching,
|
||||||
highlight,
|
highlight,
|
||||||
row - 1,
|
row,
|
||||||
start - 1,
|
start - 1,
|
||||||
finish
|
finish
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Picker:can_select_row(row)
|
function Picker:can_select_row(row)
|
||||||
@@ -597,7 +600,7 @@ function Picker:close_windows(status)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Picker:get_selection()
|
function Picker:get_selection()
|
||||||
return self._selection
|
return self._selection_entry
|
||||||
end
|
end
|
||||||
|
|
||||||
function Picker:get_selection_row()
|
function Picker:get_selection_row()
|
||||||
@@ -609,7 +612,7 @@ function Picker:move_selection(change)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Picker:reset_selection()
|
function Picker:reset_selection()
|
||||||
self._selection = nil
|
self._selection_entry = nil
|
||||||
self._selection_row = nil
|
self._selection_row = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -640,16 +643,27 @@ function Picker:set_selection(row)
|
|||||||
-- Probably something with setting a row that's too high for this?
|
-- Probably something with setting a row that's too high for this?
|
||||||
-- Not sure.
|
-- Not sure.
|
||||||
local set_ok, set_errmsg = pcall(function()
|
local set_ok, set_errmsg = pcall(function()
|
||||||
|
local prompt = vim.api.nvim_buf_get_lines(self.prompt_bufnr, 0, 1, false)[1]
|
||||||
|
|
||||||
-- Handle adding '> ' to beginning of selections
|
-- Handle adding '> ' to beginning of selections
|
||||||
if self._selection_row then
|
if self._selection_row then
|
||||||
local old_selection = a.nvim_buf_get_lines(results_bufnr, self._selection_row, self._selection_row + 1, false)[1]
|
local old_selection = a.nvim_buf_get_lines(results_bufnr, self._selection_row, self._selection_row + 1, false)[1]
|
||||||
|
|
||||||
if old_selection then
|
if old_selection then
|
||||||
a.nvim_buf_set_lines(results_bufnr, self._selection_row, self._selection_row + 1, false, {' ' .. old_selection:sub(3)})
|
local old_display = ' ' .. old_selection:sub(3)
|
||||||
|
a.nvim_buf_set_lines(results_bufnr, self._selection_row, self._selection_row + 1, false, {old_display})
|
||||||
|
|
||||||
|
if prompt and self.sorter.highlighter then
|
||||||
|
self:highlight_one_row(results_bufnr, prompt, old_display, self._selection_row)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
a.nvim_buf_set_lines(results_bufnr, row, row + 1, false, {'> ' .. (a.nvim_buf_get_lines(results_bufnr, row, row + 1, false)[1] or ''):sub(3)})
|
local display = '> ' .. (a.nvim_buf_get_lines(results_bufnr, row, row + 1, false)[1] or ''):sub(3)
|
||||||
|
|
||||||
|
-- TODO: You should go back and redraw the highlights for this line from the sorter.
|
||||||
|
-- That's the only smart thing to do.
|
||||||
|
a.nvim_buf_set_lines(results_bufnr, row, row + 1, false, {display})
|
||||||
|
|
||||||
a.nvim_buf_clear_namespace(results_bufnr, ns_telescope_selection, 0, -1)
|
a.nvim_buf_clear_namespace(results_bufnr, ns_telescope_selection, 0, -1)
|
||||||
a.nvim_buf_add_highlight(
|
a.nvim_buf_add_highlight(
|
||||||
@@ -660,6 +674,10 @@ function Picker:set_selection(row)
|
|||||||
0,
|
0,
|
||||||
-1
|
-1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if prompt and self.sorter.highlighter then
|
||||||
|
self:highlight_one_row(results_bufnr, prompt, display, row)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if not set_ok then
|
if not set_ok then
|
||||||
@@ -667,21 +685,12 @@ function Picker:set_selection(row)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if self._match_id then
|
if self._selection_entry == entry and self._selection_row == row then
|
||||||
-- -- vim.fn.matchdelete(self._match_id)
|
|
||||||
-- vim.fn.clearmatches(results_win)
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- self._match_id = vim.fn.matchaddpos("Conceal", { {row + 1, 1, 2} }, 0, -1, { window = results_win, conceal = ">" })
|
|
||||||
if self._selection == entry and self._selection_row == row then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO: Don't let you go over / under the buffer limits
|
|
||||||
-- TODO: Make sure you start exactly at the bottom selected
|
|
||||||
|
|
||||||
-- TODO: Get row & text in the same obj
|
-- TODO: Get row & text in the same obj
|
||||||
self._selection = entry
|
self._selection_entry = entry
|
||||||
self._selection_row = row
|
self._selection_row = row
|
||||||
|
|
||||||
if status.preview_win and self.previewer then
|
if status.preview_win and self.previewer then
|
||||||
|
|||||||
Reference in New Issue
Block a user