mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 17:23:02 +00:00
Dispatch a 'cancel' event if the user hits escape
This commit is contained in:
@@ -21,7 +21,7 @@ import { utilRebind, utilTriggerEvent } from '../util';
|
||||
var _comboTimerID;
|
||||
|
||||
export function uiCombobox(context) {
|
||||
var dispatch = d3_dispatch('accept');
|
||||
var dispatch = d3_dispatch('accept', 'cancel');
|
||||
var container = context.container();
|
||||
var _suggestions = [];
|
||||
var _values = [];
|
||||
@@ -183,6 +183,9 @@ export function uiCombobox(context) {
|
||||
function keyup() {
|
||||
switch (d3_event.keyCode) {
|
||||
case 27: // ⎋ Escape
|
||||
container.selectAll('.combobox-option.selected').each(function (d) {
|
||||
dispatch.call('cancel', this, d);
|
||||
});
|
||||
hide();
|
||||
break;
|
||||
|
||||
|
||||
@@ -159,6 +159,13 @@ export function uiFieldLocalized(field, context) {
|
||||
utilGetSetValue(input, tags.name);
|
||||
dispatch.call('change', this, tags);
|
||||
})
|
||||
.on('cancel', function() {
|
||||
// user hit escape, remove whatever is after the '-'
|
||||
var name = utilGetSetValue(input);
|
||||
name = name.split('-', 2)[0].trim();
|
||||
utilGetSetValue(input, name);
|
||||
dispatch.call('change', this, { name: name });
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user