feat: selection_strategy closest (#885)
* Added closest selection_strategy to use default_selection_index initially but prefer highest ranked match when prompt not empty * Updated supporting documentation to include selection_strategy
This commit is contained in:
@@ -221,7 +221,7 @@ EOF
|
||||
| `file_sorter` | The sorter for file lists. | [Sorters](#sorters) |
|
||||
| `generic_sorter` | The sorter for everything else. | [Sorters](#sorters) |
|
||||
| `vimgrep_arguments` | The command line argument for grep search ... TODO. | dict |
|
||||
| `selection_strategy` | What happens to the selection if the list changes. | follow/reset/row |
|
||||
| `selection_strategy` | What happens to the selection if the list changes. | follow/reset/row/closest |
|
||||
| `file_ignore_patterns` | Pattern to be ignored `{ "scratch/.*", "%.env" }` | dict |
|
||||
| `shorten_path` | Whether to shorten paths or not. | boolean |
|
||||
|
||||
|
||||
@@ -164,6 +164,7 @@ telescope.setup({opts}) *telescope.setup()*
|
||||
- "reset" (default)
|
||||
- "follow"
|
||||
- "row"
|
||||
- "closest"
|
||||
|
||||
*telescope.defaults.sorting_strategy*
|
||||
sorting_strategy: ~
|
||||
|
||||
@@ -124,7 +124,8 @@ local telescope_defaults = {
|
||||
Available options are:
|
||||
- "reset" (default)
|
||||
- "follow"
|
||||
- "row"]],
|
||||
- "row"
|
||||
- "closest"]],
|
||||
},
|
||||
|
||||
scroll_strategy = {
|
||||
|
||||
@@ -1069,6 +1069,12 @@ function Picker:get_result_completor(results_bufnr, find_id, prompt, status_upda
|
||||
else
|
||||
self:set_selection(self:get_reset_row())
|
||||
end
|
||||
elseif selection_strategy == 'closest' then
|
||||
if prompt == "" and self.default_selection_index ~= nil then
|
||||
self:set_selection(self:get_row(self.default_selection_index))
|
||||
else
|
||||
self:set_selection(self:get_reset_row())
|
||||
end
|
||||
else
|
||||
error('Unknown selection strategy: ' .. selection_strategy)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user