Skip to content

Commit

Permalink
Change focus to existing key instead of suffixing it with _1
Browse files Browse the repository at this point in the history
(re: #3625, re: #2896)
  • Loading branch information
bhousel committed Feb 6, 2019
1 parent 011f822 commit 640730d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions modules/ui/combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ export function uiCombobox(context, klass) {
function mouseup() {
input.on('mouseup.combo-input', null);
if (d3_event.button !== 0) return; // left click only
if (this !== document.activeElement) return; // exit if this input is not focused

var start = input.property('selectionStart');
var end = input.property('selectionEnd');
if (start !== end) return; // exit if user is selecting

// not showing or showing for a different field - try to show it.
var combo = container.selectAll('.combobox');
if (combo.empty() || combo.datum() !== input) {
if (combo.empty() || combo.datum() !== input.node()) {
var tOrig = _tDown;
window.setTimeout(function() {
if (tOrig !== _tDown) return; // exit if user double clicked
input.node().focus();
fetch('', function() {
show();
render();
Expand Down
16 changes: 11 additions & 5 deletions modules/ui/raw_tag_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,17 @@ export function uiRawTagEditor(context) {
}

if (kNew && kNew !== kOld) {
var match = kNew.match(/^(.*?)(?:_(\d+))?$/);
var base = match[1];
var suffix = +(match[2] || 1);
while (_tags[kNew]) { // rename key if already in use
kNew = base + '_' + suffix++;
if (_tags[kNew] !== undefined) { // key is already in use
this.value = kOld; // clear it out
list.selectAll('input.value')
.each(function(d) {
if (d.key === kNew) { // send focus to that other value combo instead
var input = d3_select(this).node();
input.focus();
input.select();
}
});
return;
}

if (kNew.indexOf('=') !== -1) {
Expand Down

0 comments on commit 640730d

Please sign in to comment.