From ad58779d09f46e6084c47c8ba08054fb1f34bf2a Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Sat, 2 Mar 2019 16:52:24 -0500 Subject: [PATCH] Press return to choose the first list item in search-to-add field --- css/80_app.css | 4 ++++ modules/ui/preset_list.js | 2 +- modules/ui/search_add.js | 13 +++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/css/80_app.css b/css/80_app.css index e28c32397..1bb832f7f 100644 --- a/css/80_app.css +++ b/css/80_app.css @@ -674,6 +674,10 @@ button.add-note svg.icon { top: 0; left: 0; } +.search-add .list-item button.choose:hover, +.search-add .list-item button.choose:focus { + background: #E6ECFF; +} .search-add .list-item button.choose.disabled { background-color: #ececec; } diff --git a/modules/ui/preset_list.js b/modules/ui/preset_list.js index 51c9f3a09..8aecda79b 100644 --- a/modules/ui/preset_list.js +++ b/modules/ui/preset_list.js @@ -91,7 +91,7 @@ export function uiPresetList(context) { var value = search.property('value'); if (d3_event.keyCode === 13 && value.length) { list.selectAll('.preset-list-item:first-child') - .each(function(d) { d.choose.call(d3_select(this).node()); }); + .each(function(d) { d.choose.call(this); }); } } diff --git a/modules/ui/search_add.js b/modules/ui/search_add.js index 0feb836d0..0c6e1c734 100644 --- a/modules/ui/search_add.js +++ b/modules/ui/search_add.js @@ -42,9 +42,18 @@ export function uiSearchAdd(context) { .attr('placeholder', t('modes.add_feature.title')) .attr('type', 'search') .call(utilNoAuto) + .on('keypress', function() { + // enter/return + if (d3_event.keyCode === 13) { + popover.selectAll('.list > .list-item:first-child button.choose') + .each(function(d) { d.choose.call(this); }); + d3_event.preventDefault(); + d3_event.stopPropagation(); + } + }) .on('focus', function() { - search.attr('focusing', true); search.node().setSelectionRange(0, search.property('value').length); + search.attr('focusing', true); popover.classed('hide', false); }) .on('blur', function() { @@ -52,8 +61,8 @@ export function uiSearchAdd(context) { }) .on('click', function() { if (search.attr('focusing')) { - search.attr('focusing', null); search.node().setSelectionRange(0, search.property('value').length); + search.attr('focusing', null); d3_event.preventDefault(); d3_event.stopPropagation(); }