summaryrefslogtreecommitdiff
path: root/lua/telescope
diff options
context:
space:
mode:
authorSimon Hauser <Simon-Hauser@outlook.de>2022-03-13 20:04:32 +0100
committerGitHub <noreply@github.com>2022-03-13 20:04:32 +0100
commit2532b98d6747230bb8e55753aa992bea267540a1 (patch)
treead4b23009fb76dde4d8f2be0dbb5c1621877c65a /lua/telescope
parent9f0dd2e40248be826f1e6c5b9dd8ff2bd7b2073d (diff)
fix: selection strategy madness if its not set to `reset` (#1559)
* fix: selection strategy madness when its not row * fix: selection_strategy row
Diffstat (limited to 'lua/telescope')
-rw-r--r--lua/telescope/pickers.lua22
1 files changed, 12 insertions, 10 deletions
diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua
index a9c7fb2..9edd9e9 100644
--- a/lua/telescope/pickers.lua
+++ b/lua/telescope/pickers.lua
@@ -709,9 +709,9 @@ function Picker:delete_selection(delete_cb)
end
self:refresh()
- vim.schedule(function()
+ vim.defer_fn(function()
self.selection_strategy = original_selection_strategy
- end)
+ end, 50)
end
function Picker:set_prompt(str)
@@ -755,7 +755,16 @@ end
--- Get the row number of the current selection
---@return number
function Picker:get_selection_row()
- return self._selection_row or self.max_results
+ if self._selection_row then
+ -- If the current row is no longer selectable than reduce it to num_results - 1, so the next selectable row.
+ -- This makes selection_strategy `row` work much better if the selected row is no longer part of the output.
+ local num_results = self.manager:num_results()
+ if num_results <= self._selection_row then
+ return num_results - 1
+ end
+ return self._selection_row
+ end
+ return self.max_results
end
--- Move the current selection by `change` steps
@@ -1277,13 +1286,6 @@ function Picker:get_result_processor(find_id, prompt, status_updater)
end
self.sorter:score(prompt, entry, cb_add, cb_filter)
-
- -- Only on the first addition do we want to set the selection.
- -- This allows us to handle moving the cursor to the bottom or top of the window
- -- depending on the strategy.
- if count == 1 then
- self:_do_selection(prompt)
- end
end
end