mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-20 15:34:49 +02:00
Exclude presets with searchable: false from search (fixes #932)
This commit is contained in:
@@ -41,10 +41,14 @@ iD.presets.Collection = function(collection) {
|
||||
|
||||
value = value.toLowerCase();
|
||||
|
||||
var leading_name = _.filter(collection, function(a) {
|
||||
var searchable = _.filter(collection, function(a) {
|
||||
return a.searchable !== false;
|
||||
});
|
||||
|
||||
var leading_name = _.filter(searchable, function(a) {
|
||||
return leading(a.name().toLowerCase());
|
||||
}),
|
||||
leading_terms = _.filter(collection, function(a) {
|
||||
leading_terms = _.filter(searchable, function(a) {
|
||||
return _.any(a.terms || [], leading);
|
||||
});
|
||||
|
||||
@@ -53,7 +57,7 @@ iD.presets.Collection = function(collection) {
|
||||
return index === 0 || a[index - 1] === ' ';
|
||||
}
|
||||
|
||||
var levenstein_name = collection.map(function(a) {
|
||||
var levenstein_name = searchable.map(function(a) {
|
||||
return {
|
||||
preset: a,
|
||||
dist: iD.util.editDistance(value, a.name().toLowerCase())
|
||||
@@ -65,7 +69,7 @@ iD.presets.Collection = function(collection) {
|
||||
}).map(function(a) {
|
||||
return a.preset;
|
||||
}),
|
||||
leventstein_terms = _.filter(collection, function(a) {
|
||||
leventstein_terms = _.filter(searchable, function(a) {
|
||||
return _.any(a.terms || [], function(b) {
|
||||
return iD.util.editDistance(value, b) + Math.min(value.length - b.length, 0) < 3;
|
||||
});
|
||||
|
||||
@@ -54,6 +54,15 @@ describe("iD.presets.Collection", function() {
|
||||
it("always includes other", function() {
|
||||
expect(c.search("blade of grass").collection.indexOf(p.other) >= 0).to.eql(true);
|
||||
});
|
||||
});
|
||||
|
||||
it("excludes presets with searchable: false", function() {
|
||||
var excluded = iD.presets.Preset('excluded', {
|
||||
tags: {},
|
||||
geometry: [],
|
||||
searchable: false
|
||||
}),
|
||||
collection = iD.presets.Collection([excluded, p.other]);
|
||||
expect(collection.search("excluded").collection).not.to.include(excluded);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user