Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add double-click locking of draw mode #5908

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions css/80_app.css
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ button.disabled {
color: rgba(0,0,0,.4);
cursor: not-allowed;
}
button.locked {
background: #5b637d;
color: #fff;
}

.joined button {
border-radius: 0;
Expand Down
10 changes: 9 additions & 1 deletion modules/core/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,18 @@ export function coreContext() {


/* Modes */
var mode;
var mode, lockedMode;
context.mode = function() {
return mode;
};
context.lockMode = function(mode) {
if (mode) lockedMode = mode;
return lockedMode;
};
context.unlockMode = function() {
lockedMode = null;
};

context.enter = function(newMode) {
if (mode) {
mode.exit();
Expand Down
5 changes: 5 additions & 0 deletions modules/modes/add_point.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export function modeAddPoint(context) {
context.enter(
modeSelect(context, [node.id]).newFeature(true)
);

//Re-activate mode for locked drawing mode
if (context.lockMode()) {
context.enter(context.lockMode());
}
}


Expand Down
5 changes: 5 additions & 0 deletions modules/modes/draw_area.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export function modeDrawArea(context, wayId, startGraph) {

if (node.id === way.first() || node.id === penultimate) {
behavior.finish();

//Re-activate locked drawing mode
if (context.lockMode()) {
context.enter(context.lockMode());
}
} else {
addNode(node, d);
}
Expand Down
5 changes: 5 additions & 0 deletions modules/modes/draw_line.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export function modeDrawLine(context, wayID, startGraph, affix, continuing) {
behavior.addNode = function(node, d) {
if (node.id === headID) {
behavior.finish();

//Re-activate locked drawing mode
if (context.lockMode()) {
context.enter(context.lockMode());
}
} else {
addNode(node, d);
}
Expand Down
40 changes: 27 additions & 13 deletions modules/ui/modes.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export function uiModes(context) {
context
.on('enter.editor', function(entered) {
selection.selectAll('button.add-button')
.classed('active', function(mode) { return entered.button === mode.button; });
.classed('active', function(mode) { return entered.button === mode.button; })
.classed('locked', function(mode) { return context.lockMode() != null && context.lockMode().id === mode.id; });
context.container()
.classed('mode-' + entered.id, true);
});
Expand All @@ -76,6 +77,27 @@ export function uiModes(context) {


var debouncedUpdate = _debounce(update, 500, { leading: true, trailing: true });
var debouncedClick = _debounce(clickModeButton, 300);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@quincylvania Not sure if a debounced function is the best way to support a click and a dblclick on an element, but it works for my click rate.


function clickModeButton(d, isDblClick) {
if (!enabled(d)) return;

// When drawing, ignore accidental clicks on mode buttons - #4042
var currMode = context.mode().id;
if (/^draw/.test(currMode)) return;

if (isDblClick === true) {
context.lockMode(d);
} else {
context.unlockMode();
}

if (d.id === currMode) {
context.enter(modeBrowse(context));
} else {
context.enter(d);
}
}

context.map()
.on('move.modes', debouncedUpdate)
Expand Down Expand Up @@ -103,18 +125,10 @@ export function uiModes(context) {
.append('button')
.attr('tabindex', -1)
.attr('class', function(d) { return d.id + ' add-button'; })
.on('click.mode-buttons', function(d) {
if (!enabled(d)) return;

// When drawing, ignore accidental clicks on mode buttons - #4042
var currMode = context.mode().id;
if (/^draw/.test(currMode)) return;

if (d.id === currMode) {
context.enter(modeBrowse(context));
} else {
context.enter(d);
}
.on('click.mode-buttons', debouncedClick)
.on('dblclick.mode-buttons', function(d) {
debouncedClick.cancel(); //cancel single click
clickModeButton(d, true /*dblclick*/);
})
.call(tooltip()
.placement('bottom')
Expand Down