diff options
| author | Julian Fricker <402357+TC72@users.noreply.github.com> | 2022-01-09 18:43:06 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-09 19:43:06 +0100 |
| commit | 5060f3f0ab33504e728a8673dc08679947c35ded (patch) | |
| tree | adc649dd91bb4131da32c3da647c8a81175470c4 /lua/telescope | |
| parent | e8ef88bfcbabde42b7a29e938dc5ebbdbb8b1c5f (diff) | |
feat: tiebreak config function (#1401)
Co-authored-by: Simon Hauser <Simon-Hauser@outlook.de>
Diffstat (limited to 'lua/telescope')
| -rw-r--r-- | lua/telescope/config.lua | 19 | ||||
| -rw-r--r-- | lua/telescope/entry_manager.lua | 4 | ||||
| -rw-r--r-- | lua/telescope/pickers.lua | 4 |
3 files changed, 24 insertions, 3 deletions
diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua index 043ac8a..5bf8602 100644 --- a/lua/telescope/config.lua +++ b/lua/telescope/config.lua @@ -154,6 +154,25 @@ append( ) append( + "tiebreak", + function(current_entry, existing_entry, _) + return #current_entry.ordinal < #existing_entry.ordinal + end, + [[ + A function that determines how to break a tie when two entries have + the same score. + Having a function that always returns false would keep the entries in + the order they are found, so existing_entry before current_entry. + Vice versa always returning true would place the current_entry + before the existing_entry. + + Signature: function(current_entry, existing_entry, prompt) -> boolean + + Default: function that breaks the tie based on the length of the + entry's ordinal]] +) + +append( "selection_strategy", "reset", [[ diff --git a/lua/telescope/entry_manager.lua b/lua/telescope/entry_manager.lua index 1e94c80..a8331e4 100644 --- a/lua/telescope/entry_manager.lua +++ b/lua/telescope/entry_manager.lua @@ -105,7 +105,7 @@ function EntryManager:_append_container(picker, new_container, should_update) end end -function EntryManager:add_entry(picker, score, entry) +function EntryManager:add_entry(picker, score, entry, prompt) score = score or 0 local max_res = self.max_results @@ -137,7 +137,7 @@ function EntryManager:add_entry(picker, score, entry) return self:_insert_container_before(picker, index, node, new_container) end - if score < 1 and container[2] == score and #entry.ordinal < #container[1].ordinal then + if score < 1 and container[2] == score and picker.tiebreak(entry, container[1], prompt) then return self:_insert_container_before(picker, index, node, new_container) end diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index 9385a49..6e966a5 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -105,6 +105,7 @@ function Picker:new(opts) scroll_strategy = get_default(opts.scroll_strategy, config.values.scroll_strategy), sorting_strategy = get_default(opts.sorting_strategy, config.values.sorting_strategy), + tiebreak = get_default(opts.tiebreak, config.values.tiebreak), selection_strategy = get_default(opts.selection_strategy, config.values.selection_strategy), layout_strategy = layout_strategy, @@ -1210,7 +1211,8 @@ function Picker:get_result_processor(find_id, prompt, status_updater) local count = 0 local cb_add = function(score, entry) - self.manager:add_entry(self, score, entry) + -- may need the prompt for tiebreak + self.manager:add_entry(self, score, entry, prompt) status_updater { completed = false } end |
