From 9ceceeb59a95919e5fe09338dc27e4fac0b5aa24 Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Sat, 19 Nov 2022 15:18:40 +0000 Subject: Sort items in normal tofi mode when using history. This is a short-term workaround for history sorting not working, due to the binary search used to find exiting items relying on the input already being sorted. --- src/main.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 7a9fc0c..448c164 100644 --- a/src/main.c +++ b/src/main.c @@ -1347,12 +1347,15 @@ int main(int argc, char *argv[]) string_vec_add(&tofi.window.entry.commands, line); } free(line); - if (tofi.history_file[0] == 0) { - tofi.use_history = false; - } else { - tofi.window.entry.history = history_load(tofi.history_file); + if (tofi.use_history) { + if (tofi.history_file[0] == 0) { + tofi.use_history = false; + } else { + string_vec_sort(&tofi.window.entry.commands); + tofi.window.entry.history = history_load(tofi.history_file); + compgen_history_sort(&tofi.window.entry.commands, &tofi.window.entry.history); + } } - compgen_history_sort(&tofi.window.entry.commands, &tofi.window.entry.history); } tofi.window.entry.results = string_vec_copy(&tofi.window.entry.commands); -- cgit v1.2.3