diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2021-07-17 08:15:07 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2021-07-17 08:49:54 +0200 |
commit | e948741864636b04aa0159ea02bcc3109dfbd43c (patch) | |
tree | 18ec7207c56e589b61c8c6718b119454393ed3a4 /sdn.cpp | |
parent | 0adbac2066d35c7341329766893a3b1b90008d33 (diff) | |
download | sdn-e948741864636b04aa0159ea02bcc3109dfbd43c.tar.gz sdn-e948741864636b04aa0159ea02bcc3109dfbd43c.tar.xz sdn-e948741864636b04aa0159ea02bcc3109dfbd43c.zip |
Enable pushing the search in a certain direction
We want to make it possible to iterate all current matches.
Diffstat (limited to 'sdn.cpp')
-rw-r--r-- | sdn.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -989,10 +989,11 @@ fun show_help () { fclose (contents); } -fun search (const wstring &needle) -> int { - int best = g.cursor, best_n = 0, matches = 0; - for (int i = 0; i < int (g.entries.size ()); i++) { - auto o = (i + g.cursor) % g.entries.size (); +/// Stays on the current match when there are no better ones, unless it's pushed +fun search (const wstring &needle, int push) -> int { + int best = g.cursor, best_n = 0, matches = 0, step = push != 0 ? push : 1; + for (int i = 0, count = g.entries.size (); i < count; i++) { + auto o = (g.cursor + (count + i * step) + (count + push)) % count; int n = prefix_length (to_wide (g.entries[o].filename), needle); matches += n == needle.size (); if (n > best_n) { @@ -1060,7 +1061,7 @@ fun pop_levels (const string& old_cwd) { fix_cursor_and_offset (); if (!anchor.empty () && at_cursor ().filename != anchor) - search (to_wide (anchor)); + search (to_wide (anchor), 0); } fun explode_path (const string &path, vector<string> &out) { @@ -1375,7 +1376,7 @@ fun handle (wint_t c) -> bool { case ACTION_SEARCH: g.editor = L"search"; g.editor_on_change = [] { - search (g.editor_line); + search (g.editor_line, 0); }; g.editor_on_confirm = [] { choose (at_cursor ()); |