Fixup prefix matching

develop
Robob27 2023-02-02 22:46:32 -05:00
parent cece0bfca1
commit 36e4bba779
3 changed files with 6 additions and 10 deletions

@ -2422,10 +2422,8 @@ bool Core::SelectHotkey(int sym, int modifiers)
if (!binding.focus.empty()) {
bool found = false;
std::vector<std::string> focusStrings = Gui::getFocusStrings(Core::getTopViewscreen());
for (std::string focusString : focusStrings) {
if (prefix_matches(binding.focus, focusString)) {
found = true;
}
if(Gui::matchFocusString(binding.focus)) {
found = true;
}
if (!found) {

@ -481,7 +481,7 @@ bool Gui::matchFocusString(std::string focusString, bool prefixMatch) {
std::vector<std::string> currentFocusStrings = getFocusStrings(getCurViewscreen(true));
return std::find_if(currentFocusStrings.begin(), currentFocusStrings.end(), [&focusString, &prefixMatch](std::string item) {
return prefixMatch ? toLower(item).rfind(focusString, 0) == 0 : focusString == toLower(item);
return prefixMatch ? prefix_matches(focusString, toLower(item)) : focusString == toLower(item);
}) != currentFocusStrings.end();
}

@ -109,11 +109,9 @@ static void find_active_keybindings(df::viewscreen *screen, bool filtermenu) {
vector<string> tokens;
split_string(&tokens, *invoke_cmd, ":");
string focus = tokens[0].substr(1);
for(string focusString : focusStrings) {
if (prefix_matches(toLower(focus), toLower(focusString))) {
auto cmdline = trim(tokens[1]);
add_binding_if_valid(sym, cmdline, screen, filtermenu);
}
if(Gui::matchFocusString(focus)) {
auto cmdline = trim(tokens[1]);
add_binding_if_valid(sym, cmdline, screen, filtermenu);
}
}
}