typeahead: Replace ~ operator with includes().

Before ES2016, `indexOf` and jQuery's `inArray`
were used more often. They return -1 for a missing
element, and 0 is the only integer that’s falsy, so
-1 is the only integer whose bitwise complement is
falsy. Using bitwise not (~) like this is no longer
common practice and is a lot more confusing to read.
Now that we have `includes` we can use that instead.
This commit is contained in:
evykassirer
2024-03-01 14:18:50 -08:00
committed by Tim Abbott
parent 2085d90736
commit b034875216

View File

@@ -340,7 +340,7 @@ import {get_string_diff} from "../../src/util";
},
matcher(item) {
return ~item.toLowerCase().indexOf(this.query.toLowerCase());
return item.toLowerCase().includes(this.query.toLowerCase());
},
sorter(items) {
@@ -352,7 +352,7 @@ import {get_string_diff} from "../../src/util";
while ((item = items.shift())) {
if (!item.toLowerCase().indexOf(this.query.toLowerCase())) {
beginswith.push(item);
} else if (~item.indexOf(this.query)) {
} else if (item.includes(this.query)) {
caseSensitive.push(item);
} else {
caseInsensitive.push(item);
@@ -513,7 +513,7 @@ import {get_string_diff} from "../../src/util";
e.preventDefault();
this.select(e);
}
this.suppressKeyPressRepeat = !~$.inArray(pseudo_keycode, [40, 38, 9, 13, 27]);
this.suppressKeyPressRepeat = ![40, 38, 9, 13, 27].includes(pseudo_keycode);
this.move(e);
},