feat: none strategy & control attachment (#1867)
This commit is contained in:
committed by
Simon Hauser
parent
5510587ff4
commit
a1aec79cb1
@@ -142,6 +142,7 @@ telescope.setup({opts}) *telescope.setup()*
|
|||||||
- "follow"
|
- "follow"
|
||||||
- "row"
|
- "row"
|
||||||
- "closest"
|
- "closest"
|
||||||
|
- "none"
|
||||||
|
|
||||||
*telescope.defaults.scroll_strategy*
|
*telescope.defaults.scroll_strategy*
|
||||||
scroll_strategy: ~
|
scroll_strategy: ~
|
||||||
|
|||||||
@@ -182,7 +182,8 @@ append(
|
|||||||
- "reset" (default)
|
- "reset" (default)
|
||||||
- "follow"
|
- "follow"
|
||||||
- "row"
|
- "row"
|
||||||
- "closest"]]
|
- "closest"
|
||||||
|
- "none"]]
|
||||||
)
|
)
|
||||||
|
|
||||||
append(
|
append(
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ function Picker:new(opts)
|
|||||||
_original_mode = vim.api.nvim_get_mode().mode,
|
_original_mode = vim.api.nvim_get_mode().mode,
|
||||||
debounce = get_default(tonumber(opts.debounce), nil),
|
debounce = get_default(tonumber(opts.debounce), nil),
|
||||||
|
|
||||||
|
_finder_attached = true,
|
||||||
default_text = opts.default_text,
|
default_text = opts.default_text,
|
||||||
get_status_text = get_default(opts.get_status_text, config.values.get_status_text),
|
get_status_text = get_default(opts.get_status_text, config.values.get_status_text),
|
||||||
_on_input_filter_cb = opts.on_input_filter_cb or function() end,
|
_on_input_filter_cb = opts.on_input_filter_cb or function() end,
|
||||||
@@ -505,10 +506,12 @@ function Picker:find()
|
|||||||
-- Register attach
|
-- Register attach
|
||||||
vim.api.nvim_buf_attach(prompt_bufnr, false, {
|
vim.api.nvim_buf_attach(prompt_bufnr, false, {
|
||||||
on_lines = function(...)
|
on_lines = function(...)
|
||||||
|
if self._finder_attached then
|
||||||
find_id = self:_next_find_id()
|
find_id = self:_next_find_id()
|
||||||
|
|
||||||
status_updater { completed = false }
|
status_updater { completed = false }
|
||||||
self._on_lines(...)
|
self._on_lines(...)
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_detach = function()
|
on_detach = function()
|
||||||
@@ -1365,6 +1368,16 @@ function Picker:_do_selection(prompt)
|
|||||||
else
|
else
|
||||||
self:set_selection(self:get_reset_row())
|
self:set_selection(self:get_reset_row())
|
||||||
end
|
end
|
||||||
|
elseif selection_strategy == "none" then
|
||||||
|
if self._selection_entry then
|
||||||
|
local old_entry, old_row = self._selection_entry, self._selection_row
|
||||||
|
self:reset_selection() -- required to reset selection before updating prefix
|
||||||
|
if old_row >= 0 then
|
||||||
|
self:update_prefix(old_entry, old_row)
|
||||||
|
self.highlighter:hi_multiselect(old_row, self:is_multi_selected(old_entry))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return
|
||||||
else
|
else
|
||||||
error("Unknown selection strategy: " .. selection_strategy)
|
error("Unknown selection strategy: " .. selection_strategy)
|
||||||
end
|
end
|
||||||
@@ -1495,6 +1508,11 @@ function Picker:_reset_highlights()
|
|||||||
vim.api.nvim_buf_clear_namespace(self.results_bufnr, ns_telescope_matching, 0, -1)
|
vim.api.nvim_buf_clear_namespace(self.results_bufnr, ns_telescope_matching, 0, -1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Toggles whether finder is attached to prompt buffer input
|
||||||
|
function Picker:_toggle_finder_attach()
|
||||||
|
self._finder_attached = not self._finder_attached
|
||||||
|
end
|
||||||
|
|
||||||
function Picker:_detach()
|
function Picker:_detach()
|
||||||
self.finder:close()
|
self.finder:close()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user