mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1618662 - Use a single |Intl.Collator| object to do diacritics-ignoring comparisons in URL bar autocomplete highlighting. r=AlexHenrie,mak
Differential Revision: https://phabricator.services.mozilla.com/D65235 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
0a08960bb5
commit
9962a9df84
@ -276,6 +276,8 @@ var UrlbarUtils = {
|
||||
return mimeStream.QueryInterface(Ci.nsIInputStream);
|
||||
},
|
||||
|
||||
_compareIgnoringDiacritics: null,
|
||||
|
||||
/**
|
||||
* Returns a list of all the token substring matches in a string. Matching is
|
||||
* case insensitive. Each match in the returned list is a tuple: [matchIndex,
|
||||
@ -302,6 +304,7 @@ var UrlbarUtils = {
|
||||
let hits = new Array(str.length).fill(
|
||||
highlightType == this.HIGHLIGHT.SUGGESTED ? 1 : 0
|
||||
);
|
||||
let compareIgnoringDiacritics;
|
||||
for (let { lowerCaseValue: needle } of tokens) {
|
||||
// Ideally we should never hit the empty token case, but just in case
|
||||
// the `needle` check protects us from an infinite loop.
|
||||
@ -327,11 +330,18 @@ var UrlbarUtils = {
|
||||
// If that fails to match anything, try a (computationally intensive)
|
||||
// diacritic-insensitive search.
|
||||
if (!found) {
|
||||
const options = { sensitivity: "base" };
|
||||
if (!compareIgnoringDiacritics) {
|
||||
if (!this._compareIgnoringDiacritics) {
|
||||
this._compareIgnoringDiacritics = new Intl.Collator(undefined, {
|
||||
sensitivity: "base",
|
||||
}).compare;
|
||||
}
|
||||
compareIgnoringDiacritics = this._compareIgnoringDiacritics;
|
||||
}
|
||||
index = 0;
|
||||
while (index < str.length) {
|
||||
let hay = str.substr(index, needle.length);
|
||||
if (needle.localeCompare(hay, [], options) == 0) {
|
||||
if (compareIgnoringDiacritics(needle, hay) === 0) {
|
||||
hits.fill(
|
||||
highlightType == this.HIGHLIGHT.SUGGESTED ? 0 : 1,
|
||||
index,
|
||||
|
Loading…
Reference in New Issue
Block a user