Make search() return the number of matches
This commit is contained in:
parent
2238db5a4e
commit
0adbac2066
6
sdn.cpp
6
sdn.cpp
|
@ -989,17 +989,19 @@ fun show_help () {
|
||||||
fclose (contents);
|
fclose (contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
fun search (const wstring &needle) {
|
fun search (const wstring &needle) -> int {
|
||||||
int best = g.cursor, best_n = 0;
|
int best = g.cursor, best_n = 0, matches = 0;
|
||||||
for (int i = 0; i < int (g.entries.size ()); i++) {
|
for (int i = 0; i < int (g.entries.size ()); i++) {
|
||||||
auto o = (i + g.cursor) % g.entries.size ();
|
auto o = (i + g.cursor) % g.entries.size ();
|
||||||
int n = prefix_length (to_wide (g.entries[o].filename), needle);
|
int n = prefix_length (to_wide (g.entries[o].filename), needle);
|
||||||
|
matches += n == needle.size ();
|
||||||
if (n > best_n) {
|
if (n > best_n) {
|
||||||
best = o;
|
best = o;
|
||||||
best_n = n;
|
best_n = n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g.cursor = best;
|
g.cursor = best;
|
||||||
|
return matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fix_cursor_and_offset () {
|
fun fix_cursor_and_offset () {
|
||||||
|
|
Loading…
Reference in New Issue