summaryrefslogtreecommitdiff
path: root/src/insert_completer.cc
diff options
context:
space:
mode:
authorJohannes Altmanninger <aclopte@gmail.com>2023-11-18 09:12:05 +0100
committerJohannes Altmanninger <aclopte@gmail.com>2023-12-02 10:43:59 +0100
commit658c3385a924ddfa784ab3346a56e2d96c9155a3 (patch)
treefe80f7934d8a4de04a9674857adfe42cc6a67e04 /src/insert_completer.cc
parentd6215dc25d02d1f8d958d3f5ee5c2d8b39d48e77 (diff)
ranked match: prefer input order over alphabetical order for user-specified completions
When using either of set-option g completers option=my_option prompt -shell-script-candidates ... While the search text is empty, the completions will be sorted alphabetically. This is bad because it means the most important entries are not listed first, making them harder to select or even spot. Let's apply input order before resorting to sorting alphabetically. In theory there is a more elegant solution: sort candidates (except if they're user input) before passing them to RankedMatch, and then always use stable sort. However that doesn't work because we use a heap which doesn't support stable sort. Closes #1709, #4813
Diffstat (limited to 'src/insert_completer.cc')
-rw-r--r--src/insert_completer.cc3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/insert_completer.cc b/src/insert_completer.cc
index c43d9761..af387506 100644
--- a/src/insert_completer.cc
+++ b/src/insert_completer.cc
@@ -298,10 +298,11 @@ InsertCompletion complete_option(const SelectionList& sels,
StringView query = buffer.substr(coord, cursor_pos);
Vector<RankedMatchAndInfo> matches;
- for (auto& candidate : opt.list)
+ for (auto&& [i, candidate] : opt.list | enumerate())
{
if (RankedMatchAndInfo match{std::get<0>(candidate), query})
{
+ match.set_input_sequence_number(i);
match.on_select = std::get<1>(candidate);
auto& menu = std::get<2>(candidate);
match.menu_entry = not menu.empty() ?