fix: check if caret is present before removal (#1390)
This commit is contained in:
@@ -837,10 +837,14 @@ 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 removing '> ' from beginning of previous selection (if still visible)
|
-- This block handles removing the caret from beginning of previous selection (if still visible)
|
||||||
|
-- Check if previous selection is still visible
|
||||||
if self._selection_entry and self.manager:find_entry(self._selection_entry) then
|
if self._selection_entry and self.manager:find_entry(self._selection_entry) then
|
||||||
-- Find the (possibly new) row of the old selection
|
-- Find the (possibly new) row of the old selection
|
||||||
local row_old_selection = self:get_row(self.manager:find_entry(self._selection_entry))
|
local row_old_selection = self:get_row(self.manager:find_entry(self._selection_entry))
|
||||||
|
local line = a.nvim_buf_get_lines(results_bufnr, row_old_selection, row_old_selection + 1, false)[1]
|
||||||
|
--Check if that row still has the caret
|
||||||
|
if string.sub(line, 0, #self.selection_caret) == self.selection_caret then
|
||||||
-- 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,
|
||||||
@@ -852,6 +856,7 @@ function Picker:set_selection(row)
|
|||||||
)
|
)
|
||||||
self.highlighter:hi_multiselect(row_old_selection, self:is_multi_selected(self._selection_entry))
|
self.highlighter:hi_multiselect(row_old_selection, self:is_multi_selected(self._selection_entry))
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local caret = self.selection_caret
|
local caret = self.selection_caret
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user