summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom <tapayne88@users.noreply.github.com>2021-07-02 11:42:25 +0100
committerGitHub <noreply@github.com>2021-07-02 12:42:25 +0200
commitc5a6ed16e2022e2d19936e00a8a39a97cba39f11 (patch)
tree06ef437e6c5f5c7025dc49d7c6eba4df2b56c91f
parent50001d4965af3c95614b1423ab6d130068319cd9 (diff)
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
-rw-r--r--README.md2
-rw-r--r--doc/telescope.txt1
-rw-r--r--lua/telescope/config.lua3
-rw-r--r--lua/telescope/pickers.lua6
4 files changed, 10 insertions, 2 deletions
diff --git a/README.md b/README.md
index 079a124..1d8e996 100644
--- a/README.md
+++ b/README.md
@@ -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 |
diff --git a/doc/telescope.txt b/doc/telescope.txt
index d2ed4ec..37f2b8d 100644
--- a/doc/telescope.txt
+++ b/doc/telescope.txt
@@ -164,6 +164,7 @@ telescope.setup({opts}) *telescope.setup()*
- "reset" (default)
- "follow"
- "row"
+ - "closest"
*telescope.defaults.sorting_strategy*
sorting_strategy: ~
diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua
index 847f067..01d3bc9 100644
--- a/lua/telescope/config.lua
+++ b/lua/telescope/config.lua
@@ -124,7 +124,8 @@ local telescope_defaults = {
Available options are:
- "reset" (default)
- "follow"
- - "row"]],
+ - "row"
+ - "closest"]],
},
scroll_strategy = {
diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua
index f8a0eea..e4c73e2 100644
--- a/lua/telescope/pickers.lua
+++ b/lua/telescope/pickers.lua
@@ -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