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

Inventory - Use regex in searchbar #759

Merged
merged 2 commits into from
Jan 25, 2024
Merged
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
11 changes: 9 additions & 2 deletions addons/inventory/functions/fnc_refresh.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ private _ctrlList = _display displayCtrl IDC_LIST;
lnbClear _ctrlList;

// Allow for items to be searched using class names by adding the 'class ' prefix
private _filter = toLower ctrlText (_display displayCtrl IDC_SEARCH_BAR);
private _filter = ctrlText (_display displayCtrl IDC_SEARCH_BAR);
private _filterByClass = _filter select [0, 6] == "class ";

if (_filterByClass) then {
_filter = _filter select [6];
};

if (_filter != "") then {
_filter = _filter regexReplace ["[.?*+^$[\]\\(){}|-]/gio", "\\$&"]; // escape regex characters, TODO: switch to CBA function when that's a thing
_filter = ".*?" + (_filter splitString " " joinString ".*?") + ".*?/io";
} else {
_filter = ".*?/io"
};

// Function that populates the list with the specified items using the amounts from the given cargo array
private _fnc_populate = {
params ["_cargo", "_items"];
Expand All @@ -45,7 +52,7 @@ private _fnc_populate = {
// Handle searching items by display name or class name
private _text = [_name, _x] select _filterByClass;

if (_filter in toLower _text) then {
if (_text regexMatch _filter) then {
private _picture = getText (_config >> "picture");
private _tooltip = format ["%1\n%2", _name, _x];
private _count = _counts param [_types find _x, 0];
Expand Down
Loading