fix: selection strategy madness if its not set to reset (#1559)

* fix: selection strategy madness when its not row

* fix: selection_strategy row
This commit is contained in:
Simon Hauser
2022-03-13 20:04:32 +01:00
committed by GitHub
parent 9f0dd2e402
commit 2532b98d67

View File

@@ -709,9 +709,9 @@ function Picker:delete_selection(delete_cb)
end end
self:refresh() self:refresh()
vim.schedule(function() vim.defer_fn(function()
self.selection_strategy = original_selection_strategy self.selection_strategy = original_selection_strategy
end) end, 50)
end end
function Picker:set_prompt(str) function Picker:set_prompt(str)
@@ -755,7 +755,16 @@ end
--- Get the row number of the current selection --- Get the row number of the current selection
---@return number ---@return number
function Picker:get_selection_row() 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 end
--- Move the current selection by `change` steps --- Move the current selection by `change` steps
@@ -1277,13 +1286,6 @@ function Picker:get_result_processor(find_id, prompt, status_updater)
end end
self.sorter:score(prompt, entry, cb_add, cb_filter) 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
end end