Improve some typeahead matching behaviors
Summary:
Ref T8510. Sort prefix matches above non-prefix matches, so that "Ape Discovery" does not match "discovery" better than "Discovery".
Sort functions last.
Rename function internal strings so they don't get over-promoted the prefix-match rules.
Add kind of a hack to get "Project X" sorting above all the "Project X (Milestone 1)" results.
Test Plan:
Created "Ape Discovery", "Baboon Discovery", "Chimpanzee Discovery", etc.
Main project now sorts above milestones:
{F1681773}
Prefix matches now sort above other matches:
{F1681774}
Function results (rarely used) are now less prominent:
{F1681775}
Better function results here:
{F1681776}
More function results:
{F1681777}
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T8510
Differential Revision: https://secure.phabricator.com/D16094
This commit is contained in:
@@ -184,11 +184,20 @@ JX.install('Prefab', {
|
||||
var priority_hits = {};
|
||||
var self_hits = {};
|
||||
|
||||
// We'll put matches where the user's input is a prefix of the name
|
||||
// above mathches where that isn't true.
|
||||
var prefix_hits = {};
|
||||
|
||||
var tokens = this.tokenize(value);
|
||||
var normal = this.normalize(value);
|
||||
|
||||
for (var ii = 0; ii < list.length; ii++) {
|
||||
var item = list[ii];
|
||||
|
||||
if (this.normalize(item.name).indexOf(normal) === 0) {
|
||||
prefix_hits[item.id] = true;
|
||||
}
|
||||
|
||||
for (var jj = 0; jj < tokens.length; jj++) {
|
||||
if (item.name.indexOf(tokens[jj]) === 0) {
|
||||
priority_hits[item.id] = true;
|
||||
@@ -237,6 +246,10 @@ JX.install('Prefab', {
|
||||
return priority_hits[v.id] ? 1 : -1;
|
||||
}
|
||||
|
||||
if (prefix_hits[u.id] != prefix_hits[v.id]) {
|
||||
return prefix_hits[v.id] ? 1 : -1;
|
||||
}
|
||||
|
||||
// Sort users ahead of other result types.
|
||||
if (u.priorityType != v.priorityType) {
|
||||
if (u.priorityType == 'user') {
|
||||
@@ -247,6 +260,13 @@ JX.install('Prefab', {
|
||||
}
|
||||
}
|
||||
|
||||
// Sort functions after other result types.
|
||||
var uf = (u.tokenType == 'function');
|
||||
var vf = (v.tokenType == 'function');
|
||||
if (uf != vf) {
|
||||
return uf ? 1 : -1;
|
||||
}
|
||||
|
||||
return cmp(u, v);
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user