diff --git a/js/id/presets.js b/js/id/presets.js index 2bc80cf19..db97f9420 100644 --- a/js/id/presets.js +++ b/js/id/presets.js @@ -5,7 +5,6 @@ iD.presets = function() { var all = iD.presets.Collection([]), defaults = { area: all, line: all, point: all, vertex: all }, - fallbacks = {}, fields = {}, universal = [], recent = iD.presets.Collection([]); @@ -38,7 +37,7 @@ iD.presets = function() { } } - return match || fallbacks[geometry]; + return match || all.item(geometry); }; all.load = function(d) { @@ -72,14 +71,6 @@ iD.presets = function() { }; } - fallbacks = { - point: all.item('point'), - vertex: all.item('vertex'), - line: all.item('line'), - area: all.item('area'), - relation: all.item('relation') - }; - for (var i = 0; i < all.collection.length; i++) { var preset = all.collection[i], geometry = preset.geometry; @@ -106,7 +97,7 @@ iD.presets = function() { all.defaults = function(geometry, n) { var rec = recent.matchGeometry(geometry).collection.slice(0, 4), def = _.uniq(rec.concat(defaults[geometry].collection)).slice(0, n - 1); - return iD.presets.Collection(_.unique(rec.concat(def).concat(fallbacks[geometry]))); + return iD.presets.Collection(_.unique(rec.concat(def).concat(all.item(geometry)))); }; all.choose = function(preset) { diff --git a/js/id/presets/collection.js b/js/id/presets/collection.js index 9459d8efb..176d792af 100644 --- a/js/id/presets/collection.js +++ b/js/id/presets/collection.js @@ -16,7 +16,7 @@ iD.presets.Collection = function(collection) { })); }, - search: function(value) { + search: function(value, geometry) { if (!value) return this; value = value.toLowerCase(); @@ -59,7 +59,7 @@ iD.presets.Collection = function(collection) { }); }); - var other = presets.item('other'); + var other = presets.item(geometry); return iD.presets.Collection( _.unique( diff --git a/js/id/ui/preset_list.js b/js/id/ui/preset_list.js index 24cb4dea8..f4bebfdb3 100644 --- a/js/id/ui/preset_list.js +++ b/js/id/ui/preset_list.js @@ -61,7 +61,7 @@ iD.ui.PresetList = function(context, entity) { } else { list.classed('filtered', value.length); if (value.length) { - var results = presets.search(value); + var results = presets.search(value, geometry); message.text(t('inspector.results', { n: results.collection.length, search: value diff --git a/test/spec/presets/collection.js b/test/spec/presets/collection.js index 2c86d499a..3307efc6c 100644 --- a/test/spec/presets/collection.js +++ b/test/spec/presets/collection.js @@ -1,9 +1,13 @@ describe("iD.presets.Collection", function() { var p = { - other: iD.presets.Preset('other', { + point: iD.presets.Preset('point', { tags: {}, - geometry: ['point', 'vertex', 'line', 'area'] + geometry: ['point'] + }), + area: iD.presets.Preset('area', { + tags: {}, + geometry: ['area'] }), residential: iD.presets.Preset('highway/residential', { tags: { @@ -19,7 +23,7 @@ describe("iD.presets.Collection", function() { }) }; - var c = iD.presets.Collection([p.other, p.residential]), + var c = iD.presets.Collection([p.point, p.area, p.residential, p.park]), n = iD.Node( { id: 'n1' }), w = iD.Way({ tags: { highway: 'residential' }}), g = iD.Graph().replace(w); @@ -32,21 +36,22 @@ describe("iD.presets.Collection", function() { describe("#matchGeometry", function() { it("returns a new collection only containing presets matching a geometry", function() { - expect(c.matchGeometry('line').collection).to.eql([p.other, p.residential]); + expect(c.matchGeometry('area').collection).to.eql([p.area, p.park]); }); }); describe("#search", function() { it("filters presets by name", function() { - expect(c.search("resid").collection.indexOf(p.residential) >= 0).to.eql(true); + expect(c.search("resid", "line").collection.indexOf(p.residential) >= 0).to.eql(true); }); it("is fuzzy", function() { - expect(c.search("rusid").collection.indexOf(p.residential) >= 0).to.eql(true); + expect(c.search("rusid", "line").collection.indexOf(p.residential) >= 0).to.eql(true); }); - it("always includes other", function() { - expect(c.search("blade of grass").collection.indexOf(p.other) >= 0).to.eql(true); + it("includes the appropriate fallback preset", function() { + expect(c.search("blade of grass", "point").collection.indexOf(p.point) >= 0).to.eql(true); + expect(c.search("blade of grass", "area").collection.indexOf(p.area) >= 0).to.eql(true); }); it("excludes presets with searchable: false", function() { @@ -55,8 +60,8 @@ describe("iD.presets.Collection", function() { geometry: [], searchable: false }), - collection = iD.presets.Collection([excluded, p.other]); - expect(collection.search("excluded").collection).not.to.include(excluded); + collection = iD.presets.Collection([excluded, p.point]); + expect(collection.search("excluded", "point").collection).not.to.include(excluded); }); }); });