From f56222738b719f5ae94ed85fdf080690371da0b9 Mon Sep 17 00:00:00 2001 From: Luke Kershaw <35707277+l-kershaw@users.noreply.github.com> Date: Thu, 21 Oct 2021 10:46:32 +0100 Subject: [PATCH] fix: always remove previous caret when change selection (#1364) --- lua/telescope/pickers.lua | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index f49920a..33129ca 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -833,25 +833,20 @@ function Picker:set_selection(row) local set_ok, set_errmsg = pcall(function() local prompt = self:_get_prompt() - -- Handle adding '> ' to beginning of selections - if self._selection_row then + -- Handle removing '> ' from beginning of previous selection (if still visible) + 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 a.nvim_buf_set_text( results_bufnr, - self._selection_row, + row_old_selection, 0, - self._selection_row, + row_old_selection, #self.selection_caret, { self.entry_prefix } ) - self.highlighter:hi_multiselect(self._selection_row, 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) + self.highlighter:hi_multiselect(row_old_selection, self:is_multi_selected(self._selection_entry)) end local caret = self.selection_caret