fix: always remove previous caret when change selection (#1364)

This commit is contained in:
Luke Kershaw
2021-10-21 10:46:32 +01:00
committed by GitHub
parent a0835edd86
commit f56222738b

View File

@@ -833,25 +833,20 @@ function Picker:set_selection(row)
local set_ok, set_errmsg = pcall(function() local set_ok, set_errmsg = pcall(function()
local prompt = self:_get_prompt() local prompt = self:_get_prompt()
-- Handle adding '> ' to beginning of selections -- Handle removing '> ' from beginning of previous selection (if still visible)
if self._selection_row then if self._selection_entry and self.manager:find_entry(self._selection_entry) then
-- Find the (possibly new) row of the old selection
local row_old_selection = self:get_row(self.manager:find_entry(self._selection_entry))
-- Only change the first couple characters, nvim_buf_set_text leaves the existing highlights -- Only change the first couple characters, nvim_buf_set_text leaves the existing highlights
a.nvim_buf_set_text( a.nvim_buf_set_text(
results_bufnr, results_bufnr,
self._selection_row, row_old_selection,
0, 0,
self._selection_row, row_old_selection,
#self.selection_caret, #self.selection_caret,
{ self.entry_prefix } { self.entry_prefix }
) )
self.highlighter:hi_multiselect(self._selection_row, self:is_multi_selected(self._selection_entry)) self.highlighter:hi_multiselect(row_old_selection, self:is_multi_selected(self._selection_entry))
-- local display = a.nvim_buf_get_lines(results_bufnr, old_row, old_row + 1, false)[1]
-- display = ' ' .. display
-- a.nvim_buf_set_lines(results_bufnr, old_row, old_row + 1, false, {display})
-- self.highlighter:hi_display(old_row, ' ', display_highlights)
-- self.highlighter:hi_sorter(old_row, prompt, display)
end end
local caret = self.selection_caret local caret = self.selection_caret