mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
util.js: Fix prefix_sort logic to not mutate input.
In prefix sort, shifting of objs list to iterate through the elements caused the 'emoji_show_list' to be emptied each time it was passed as argument for sorting. This modifies prefix sort to prevent it from modifying the objs list passed as argument - changed it to normal iteration rather than popping the elements from objs list.
This commit is contained in:
committed by
Tim Abbott
parent
ccd880094e
commit
27009e9708
@@ -241,10 +241,10 @@ exports.prefix_sort = function (query, objs, get_item) {
|
|||||||
var beginswithCaseSensitive = [];
|
var beginswithCaseSensitive = [];
|
||||||
var beginswithCaseInsensitive = [];
|
var beginswithCaseInsensitive = [];
|
||||||
var noMatch = [];
|
var noMatch = [];
|
||||||
|
var obj;
|
||||||
var obj = objs.shift();
|
var item;
|
||||||
while (obj) {
|
for (var i = 0; i < objs.length; i += 1) {
|
||||||
var item;
|
obj = objs[i];
|
||||||
if (get_item) {
|
if (get_item) {
|
||||||
item = get_item(obj);
|
item = get_item(obj);
|
||||||
} else {
|
} else {
|
||||||
@@ -257,7 +257,6 @@ exports.prefix_sort = function (query, objs, get_item) {
|
|||||||
} else {
|
} else {
|
||||||
noMatch.push(obj);
|
noMatch.push(obj);
|
||||||
}
|
}
|
||||||
obj = objs.shift();
|
|
||||||
}
|
}
|
||||||
return { matches: beginswithCaseSensitive.concat(beginswithCaseInsensitive),
|
return { matches: beginswithCaseSensitive.concat(beginswithCaseInsensitive),
|
||||||
rest: noMatch };
|
rest: noMatch };
|
||||||
|
|||||||
Reference in New Issue
Block a user