Skip to content

Commit

Permalink
Refine focus behavior for inspector (fixes #1277)
Browse files Browse the repository at this point in the history
Auto-focus the search field only right after finishing drawing.
At that point, the radial menu isn't shown anyway. So then the
flow for correcting geometry before assigning a preset is:

 1. Draw.
 2. Finish drawing. The search field is focused, and no
    radial menu is open.
 3. Click again to reselect the feature and show menu.
    Now the search field is blurred.

In other words: when the menu is shown, search should not be
focused. When search is focused, the menu should not be shown.
  • Loading branch information
jfirebaugh committed Apr 12, 2013
1 parent ee07b01 commit 5dda54e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
2 changes: 1 addition & 1 deletion js/id/behavior/draw_way.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ iD.behavior.DrawWay = function(context, wayId, index, mode, baseGraph) {

var way = context.entity(wayId);
if (way) {
context.enter(iD.modes.Select(context, [way.id], true));
context.enter(iD.modes.Select(context, [way.id]).newFeature(true));
} else {
context.enter(iD.modes.Browse(context));
}
Expand Down
21 changes: 16 additions & 5 deletions js/id/modes/select.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
iD.modes.Select = function(context, selection, initial) {
iD.modes.Select = function(context, selection) {
var mode = {
id: 'select',
button: 'browse'
Expand All @@ -11,15 +11,16 @@ iD.modes.Select = function(context, selection, initial) {

if (!selection.length) return iD.modes.Browse(context);

var inspector = singular() && iD.ui.Inspector(context, singular()),
keybinding = d3.keybinding('select'),
var keybinding = d3.keybinding('select'),
timeout = null,
behaviors = [
iD.behavior.Hover(),
iD.behavior.Select(context),
iD.behavior.Lasso(context),
iD.modes.DragNode(context).behavior],
radialMenu;
inspector,
radialMenu,
newFeature = false;

var wrap = context.container()
.select('.inspector-wrap');
Expand Down Expand Up @@ -51,10 +52,17 @@ iD.modes.Select = function(context, selection, initial) {
};

mode.reselect = function() {
context.surface().node().focus();
positionMenu();
showMenu();
};

mode.newFeature = function(_) {
if (!arguments.length) return newFeature;
newFeature = _;
return mode;
};

mode.enter = function() {
behaviors.forEach(function(behavior) {
context.install(behavior);
Expand Down Expand Up @@ -85,6 +93,9 @@ iD.modes.Select = function(context, selection, initial) {
}), true));

if (singular()) {
inspector = iD.ui.Inspector(context, singular())
.newFeature(newFeature);

wrap.call(inspector);
}

Expand Down Expand Up @@ -148,7 +159,7 @@ iD.modes.Select = function(context, selection, initial) {
selectElements();

radialMenu = iD.ui.RadialMenu(operations);
var show = d3.event && !initial;
var show = d3.event && !newFeature;

if (show) {
positionMenu();
Expand Down
10 changes: 9 additions & 1 deletion js/id/ui/inspector.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
iD.ui.Inspector = function(context, entity) {
var tagEditor,
id = entity.id;
id = entity.id,
newFeature = false;

function changeTags(tags) {
var entity = context.entity(id);
Expand Down Expand Up @@ -48,6 +49,7 @@ iD.ui.Inspector = function(context, entity) {
.classed('pane tag-pane', true);

var presetGrid = iD.ui.PresetGrid(context, entity)
.newFeature(newFeature)
.on('close', browse)
.on('choose', function(preset) {
var right = panewrap.style('right').indexOf('%') > 0 ? '0%' : '0px';
Expand Down Expand Up @@ -118,5 +120,11 @@ iD.ui.Inspector = function(context, entity) {
.on('change.inspector', null);
};

inspector.newFeature = function(_) {
if (!arguments.length) return newFeature;
newFeature = _;
return inspector;
};

return inspector;
};
13 changes: 11 additions & 2 deletions js/id/ui/preset_grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ iD.ui.PresetGrid = function(context, entity) {
var event = d3.dispatch('choose', 'close'),
defaultLimit = 9,
currentlyDrawn = 9,
presets;
presets,
newFeature = false;

function presetgrid(selection, preset) {

Expand Down Expand Up @@ -102,7 +103,9 @@ iD.ui.PresetGrid = function(context, entity) {
searchwrap.append('span')
.attr('class', 'icon search');

search.node().focus();
if (newFeature) {
search.node().focus();
}

function choose(d) {
// Category
Expand Down Expand Up @@ -243,5 +246,11 @@ iD.ui.PresetGrid = function(context, entity) {
}
}

presetgrid.newFeature = function(_) {
if (!arguments.length) return newFeature;
newFeature = _;
return presetgrid;
};

return d3.rebind(presetgrid, event, 'on');
};

0 comments on commit 5dda54e

Please sign in to comment.