Skip to content

Commit

Permalink
Use ⌘F to focus the feature search box
Browse files Browse the repository at this point in the history
(closes #4545)
  • Loading branch information
bhousel committed Dec 6, 2017
1 parent c6ab9e5 commit 3440b55
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 26 deletions.
1 change: 1 addition & 0 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ en:
select_one: "Select a single feature"
select_multi: "Select multiple features"
lasso: "Draw a selection lasso around features"
search: "Find features matching search text"
with_selected:
title: "With feature selected"
edit_menu: "Toggle edit menu"
Expand Down
5 changes: 3 additions & 2 deletions data/shortcuts.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@
"gesture": "shortcuts.gesture.drag",
"text": "shortcuts.browsing.selecting.lasso"
}, {
"shortcuts": [],
"text": ""
"modifiers": [""],
"shortcuts": ["F"],
"text": "shortcuts.browsing.selecting.search"
},

{
Expand Down
3 changes: 2 additions & 1 deletion dist/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,8 @@
"title": "Selecting features",
"select_one": "Select a single feature",
"select_multi": "Select multiple features",
"lasso": "Draw a selection lasso around features"
"lasso": "Draw a selection lasso around features",
"search": "Find features matching search text"
},
"with_selected": {
"title": "With feature selected",
Expand Down
80 changes: 57 additions & 23 deletions modules/ui/feature_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,37 @@ import {
select as d3_select
} from 'd3-selection';

import { d3keybinding as d3_keybinding } from '../lib/d3.keybinding.js';

import * as sexagesimal from '@mapbox/sexagesimal';
import { t } from '../util/locale';
import { geoExtent, geoChooseEdge } from '../geo/index';
import { modeSelect } from '../modes/index';
import { osmEntity } from '../osm/index';
import { svgIcon } from '../svg/index';
import { services } from '../services/index';
import { geoExtent, geoChooseEdge } from '../geo';
import { modeSelect } from '../modes';
import { osmEntity } from '../osm';
import { svgIcon } from '../svg';
import { services } from '../services';
import { uiCmd } from './cmd';

import {
utilDisplayName,
utilDisplayType,
utilEntityOrMemberSelector,
utilNoAuto
} from '../util/index';
} from '../util';


export function uiFeatureList(context) {
var geocodeResults;
var keybinding = d3_keybinding('feature-list');
var _geocodeResults;


function featureList(selection) {
var header = selection
.append('div')
.attr('class', 'header fillL cf');

header.append('h3')
header
.append('h3')
.text(t('inspector.feature_list'));

var searchWrap = selection
Expand All @@ -41,6 +46,7 @@ export function uiFeatureList(context) {
.attr('type', 'search')
.call(utilNoAuto)
.on('keypress', keypress)
.on('keydown', keydown)
.on('input', inputevent);

searchWrap
Expand All @@ -59,18 +65,40 @@ export function uiFeatureList(context) {
context.map()
.on('drawn.feature-list', mapDrawn);

keybinding
.on(uiCmd('⌘F'), focusSearch);

d3_select(document)
.call(keybinding);


function focusSearch() {
var mode = context.mode() && context.mode().id;
if (mode !== 'browse') return;

d3_event.preventDefault();
search.node().focus();
}


function keydown() {
if (d3_event.keyCode === 27) { // escape
search.node().blur();
}
}


function keypress() {
var q = search.property('value'),
items = list.selectAll('.feature-list-item');
if (d3_event.keyCode === 13 && q.length && items.size()) {
if (d3_event.keyCode === 13 && q.length && items.size()) { // return
click(items.datum());
}
}


function inputevent() {
geocodeResults = undefined;
_geocodeResults = undefined;
drawList();
}

Expand Down Expand Up @@ -149,7 +177,7 @@ export function uiFeatureList(context) {
addEntity(visible[i].__data__);
}

(geocodeResults || []).forEach(function(d) {
(_geocodeResults || []).forEach(function(d) {
// https://github.com/openstreetmap/iD/issues/1890
if (d.osm_type && d.osm_id) {
result.push({
Expand All @@ -175,11 +203,12 @@ export function uiFeatureList(context) {

list.classed('filtered', value.length);

var noResultsWorldwide = geocodeResults && geocodeResults.length === 0;
var noResultsWorldwide = _geocodeResults && _geocodeResults.length === 0;

var resultsIndicator = list.selectAll('.no-results-item')
.data([0])
.enter().append('button')
.enter()
.append('button')
.property('disabled', true)
.attr('class', 'no-results-item')
.call(svgIcon('#icon-alert', 'pre-text'));
Expand All @@ -193,7 +222,8 @@ export function uiFeatureList(context) {
if (services.geocoder) {
list.selectAll('.geocode-item')
.data([0])
.enter().append('button')
.enter()
.append('button')
.attr('class', 'geocode-item')
.on('click', geocoderSearch)
.append('div')
Expand All @@ -207,7 +237,7 @@ export function uiFeatureList(context) {
.style('display', (value.length && !results.length) ? 'block' : 'none');

list.selectAll('.geocode-item')
.style('display', (value && geocodeResults === undefined) ? 'block' : 'none');
.style('display', (value && _geocodeResults === undefined) ? 'block' : 'none');

list.selectAll('.feature-list-item')
.data([-1])
Expand All @@ -227,20 +257,24 @@ export function uiFeatureList(context) {
.append('div')
.attr('class', 'label');

label.each(function(d) {
d3_select(this)
.call(svgIcon('#icon-' + d.geometry, 'pre-text'));
});
label
.each(function(d) {
d3_select(this)
.call(svgIcon('#icon-' + d.geometry, 'pre-text'));
});

label.append('span')
label
.append('span')
.attr('class', 'entity-type')
.text(function(d) { return d.type; });

label.append('span')
label
.append('span')
.attr('class', 'entity-name')
.text(function(d) { return d.name; });

enter.style('opacity', 0)
enter
.style('opacity', 0)
.transition()
.style('opacity', 1);

Expand Down Expand Up @@ -287,7 +321,7 @@ export function uiFeatureList(context) {

function geocoderSearch() {
services.geocoder.search(search.property('value'), function (err, resp) {
geocodeResults = resp || [];
_geocodeResults = resp || [];
drawList();
});
}
Expand Down

0 comments on commit 3440b55

Please sign in to comment.