diff --git a/data/core.yaml b/data/core.yaml index 183f5e7cc..e2f925081 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -38,6 +38,8 @@ en: title: "Add {feature} as a line" area: title: "Add {feature} as an area" + building: + title: "Add {feature} as a building" vertex: title: "Add {feature} as a vertex" browse: diff --git a/dist/locales/en.json b/dist/locales/en.json index 6573e444f..731472aec 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -49,6 +49,9 @@ "area": { "title": "Add {feature} as an area" }, + "building": { + "title": "Add {feature} as a building" + }, "vertex": { "title": "Add {feature} as a vertex" } diff --git a/modules/presets/index.js b/modules/presets/index.js index 44a3694d6..d8b14f52e 100644 --- a/modules/presets/index.js +++ b/modules/presets/index.js @@ -268,6 +268,10 @@ export function presetIndex() { return presetCollection(_uniq(rec.concat(def).concat(all.item(geometry)))); }; + all.recent = function(geometries, n) { + return presetCollection(_recent.matchAnyGeometry(geometries).collection.slice(0, n - 1)); + } + all.choose = function(preset) { if (preset.searchable !== false) { _recent = presetCollection(_uniq([preset].concat(_recent.collection))); diff --git a/modules/ui/modes.js b/modules/ui/modes.js index 9d0e6beb3..394720fcf 100644 --- a/modules/ui/modes.js +++ b/modules/ui/modes.js @@ -78,7 +78,11 @@ export function uiModes(context) { }); var tooltipTitleID = 'modes.add_preset.title'; if (relevantMatchingGeometry.length !== 1) { - tooltipTitleID = 'modes.add_preset.' + d.geom + '.title'; + if (preset.setTags({}, d.geom).building) { + tooltipTitleID = 'modes.add_preset.building.title'; + } else { + tooltipTitleID = 'modes.add_preset.' + d.geom + '.title'; + } } var favoriteMode = { button: markerClass, diff --git a/modules/ui/search_add.js b/modules/ui/search_add.js index 8ce069f9b..4df8f27f7 100644 --- a/modules/ui/search_add.js +++ b/modules/ui/search_add.js @@ -132,17 +132,22 @@ export function uiSearchAdd(context) { } }) .on('input', function () { + + popover.selectAll('.subsection').remove(); + var value = search.property('value'); + var results; if (value.length) { - popover.selectAll('.subsection').remove(); - var results = presets.search(value, shownGeometry); - list.call(drawList, results); - popover.selectAll('.list .list-item.focused') - .classed('focused', false); - focusListItem(popover.selectAll('.list > .list-item:first-child')); + results = presets.search(value, shownGeometry); } else { - popover.selectAll('.list > *').remove(); + results = context.presets().recent(shownGeometry, 36); } + + list.call(drawList, results); + + popover.selectAll('.list .list-item.focused') + .classed('focused', false); + focusListItem(popover.selectAll('.list > .list-item:first-child')); }); searchWrap @@ -195,6 +200,9 @@ export function uiSearchAdd(context) { } function itemForPreset(preset) { + if (preset.members) { + return CategoryItem(preset); + } var supportedGeometry = preset.geometry.filter(function(geometry) { return shownGeometry.indexOf(geometry) !== -1; }).sort(); @@ -212,9 +220,6 @@ export function uiSearchAdd(context) { function drawList(list, presets) { var collection = presets.collection.map(function(preset) { - if (preset.members) { - return CategoryItem(preset); - } return itemForPreset(preset); }); @@ -282,6 +287,9 @@ export function uiSearchAdd(context) { label.append('span') .text(function(d) { if (d.isSubitem) { + if (d.preset.setTags({}, d.geometry).building) { + return t('presets.presets.building.name'); + } return t('modes.add_' + d.geometry + '.title'); } return d.preset.name(); @@ -417,6 +425,7 @@ export function uiSearchAdd(context) { mode = modeAddArea(context, modeInfo); } search.node().blur(); + context.presets().choose(preset); context.enter(mode); }; return item;