Skip to content

Commit

Permalink
Inventory - Use regex in searchbar (#759)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkIsGrim authored Jan 25, 2024
1 parent 07031ba commit 9ea2b6b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions addons/inventory/functions/fnc_refresh.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,21 @@ 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 {
// Escape regex characters, TODO: switch to CBA function when that's a thing
_filter = _filter regexReplace ["[.?*+^$[\]\\(){}|-]/gio", "\\$&"];
_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 +53,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

0 comments on commit 9ea2b6b

Please sign in to comment.