Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search variables using multiple words #168

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion config/menus/vars.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ menu_variables = [
q = (+ $variable_index $i)
if (< $q $numvars) [
curvar = (getvarinfo $q $variable_types $variable_no_types $variable_flags $variable_no_flags $variable_search_text)
hilvar = (stringreplace $curvar $variable_search_text (format "^fs^fy%1^fS" $variable_search_text))
hilvar = $curvar
looplist variable_search_word $variable_search_text [
hilvar = (stringreplace $hilvar $variable_search_word (format "^fs^fy%1^fS" $variable_search_word))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a comment that states exactly what this line does, it is not obvious

]
ui_list [ ui_radiobutton $hilvar variable_number $q ]
] [ ui_strut 1 ]
]
Expand Down
15 changes: 14 additions & 1 deletion src/engine/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3579,11 +3579,24 @@ void getvarinfo(int n, int types, int notypes, int flags, int noflags, char *str
}
if(str && *str)
{
std::vector<std::string> words;
explodelist(str, words);
static char *laststr = NULL;
if(ids[1].empty() || !laststr || strcmp(str, laststr))
{
ids[1].setsize(0);
loopv(ids[0]) if(rigcasestr(ids[0][i]->name, str)) ids[1].add(ids[0][i]);
loopv(ids[0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do not use loop macros, instead use for (int i = 0; i < ids[0].length(); i++)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't add that loop macro. I think getting rid of the loop macros is a separate issue for another PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I general we usually just remove them from code we rework/work at. It doesn't hurt anybody

{
bool matches = true;
for (const std::string &word : words)
{
if(!rigcasestr(ids[0][i]->name, word.c_str()))
{
matches = false;
}
}
if(matches) ids[1].add(ids[0][i]);
}
if(laststr) DELETEA(laststr);
laststr = newstring(str);
}
Expand Down