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

prevent certain keyboard shortcuts causing all work to be lost #10118

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions modules/modes/add_area.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { actionAddVertex } from '../actions/add_vertex';
import { behaviorAddWay } from '../behavior/add_way';
import { modeDrawArea } from './draw_area';
import { osmNode, osmWay } from '../osm';
import { utilIsDrawing } from '../util/util';


export function modeAddArea(context, mode) {
Expand Down Expand Up @@ -74,6 +75,7 @@ export function modeAddArea(context, mode) {
context.enter(modeDrawArea(context, way.id, startGraph, mode.button));
}

mode.disabled = () => utilIsDrawing(context.mode().id);

mode.enter = function() {
context.install(behavior);
Expand Down
2 changes: 2 additions & 0 deletions modules/modes/add_line.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { actionAddVertex } from '../actions/add_vertex';
import { behaviorAddWay } from '../behavior/add_way';
import { modeDrawLine } from './draw_line';
import { osmNode, osmWay } from '../osm';
import { utilIsDrawing } from '../util/util';


export function modeAddLine(context, mode) {
Expand Down Expand Up @@ -65,6 +66,7 @@ export function modeAddLine(context, mode) {
context.enter(modeDrawLine(context, way.id, startGraph, mode.button));
}

mode.disabled = () => utilIsDrawing(context.mode().id);

mode.enter = function() {
context.install(behavior);
Expand Down
2 changes: 2 additions & 0 deletions modules/modes/add_note.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { modeBrowse } from './browse';
import { modeSelectNote } from './select_note';
import { osmNote } from '../osm';
import { services } from '../services';
import { utilIsDrawing } from '../util/util';


export function modeAddNote(context) {
Expand Down Expand Up @@ -40,6 +41,7 @@ export function modeAddNote(context) {
context.enter(modeBrowse(context));
}

mode.disabled = () => utilIsDrawing(context.mode().id);

mode.enter = function() {
context.install(behavior);
Expand Down
2 changes: 2 additions & 0 deletions modules/modes/add_point.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { osmNode } from '../osm/node';
import { actionAddEntity } from '../actions/add_entity';
import { actionChangeTags } from '../actions/change_tags';
import { actionAddMidpoint } from '../actions/add_midpoint';
import { utilIsDrawing } from '../util/util';


export function modeAddPoint(context, mode) {
Expand Down Expand Up @@ -81,6 +82,7 @@ export function modeAddPoint(context, mode) {
context.enter(modeBrowse(context));
}

mode.disabled = () => utilIsDrawing(context.mode().id);

mode.enter = function() {
context.install(behavior);
Expand Down
3 changes: 2 additions & 1 deletion modules/svg/lines.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { svgTagClasses } from './tag_classes';
import { osmEntity, osmOldMultipolygonOuterMember } from '../osm';
import { utilArrayFlatten, utilArrayGroupBy } from '../util';
import { utilDetect } from '../util/detect';
import { utilIsDrawing } from '../util/util';

export function svgLines(projection, context) {
var detected = utilDetect();
Expand Down Expand Up @@ -119,7 +120,7 @@ export function svgLines(projection, context) {
function drawLineGroup(selection, klass, isSelected) {
// Note: Don't add `.selected` class in draw modes
var mode = context.mode();
var isDrawing = mode && /^draw/.test(mode.id);
var isDrawing = mode && utilIsDrawing(mode.id);
var selectedClass = (!isDrawing && isSelected) ? 'selected ' : '';

var lines = selection
Expand Down
1 change: 1 addition & 0 deletions modules/ui/tools/modes.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function uiToolDrawModes(context) {
modes.forEach(function(mode) {
context.keybinding().on(mode.key, function() {
if (!enabled(mode)) return;
if (mode.disabled?.()) return;

if (mode.id === context.mode().id) {
context.enter(modeBrowse(context));
Expand Down
6 changes: 6 additions & 0 deletions modules/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,3 +648,9 @@ export function utilCleanOsmString(val, maxChars) {
// trim to the number of allowed characters
return utilUnicodeCharsTruncated(val, maxChars);
}

/**
* Indicates if the current mode is a drawing mode
* @param {string} mode
*/
export const utilIsDrawing = (mode) => mode.startsWith('draw');
Loading