diff --git a/modules/modes/add_area.js b/modules/modes/add_area.js index 7932feec0c..ed3153ee2c 100644 --- a/modules/modes/add_area.js +++ b/modules/modes/add_area.js @@ -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) { @@ -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); diff --git a/modules/modes/add_line.js b/modules/modes/add_line.js index 426f4ce4be..bdf162309a 100644 --- a/modules/modes/add_line.js +++ b/modules/modes/add_line.js @@ -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) { @@ -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); diff --git a/modules/modes/add_note.js b/modules/modes/add_note.js index 71f9887cca..a69f88436b 100644 --- a/modules/modes/add_note.js +++ b/modules/modes/add_note.js @@ -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) { @@ -40,6 +41,7 @@ export function modeAddNote(context) { context.enter(modeBrowse(context)); } + mode.disabled = () => utilIsDrawing(context.mode().id); mode.enter = function() { context.install(behavior); diff --git a/modules/modes/add_point.js b/modules/modes/add_point.js index deff506a9c..408ecb6db0 100644 --- a/modules/modes/add_point.js +++ b/modules/modes/add_point.js @@ -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) { @@ -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); diff --git a/modules/svg/lines.js b/modules/svg/lines.js index ba979478d8..ade5380e45 100644 --- a/modules/svg/lines.js +++ b/modules/svg/lines.js @@ -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(); @@ -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 diff --git a/modules/ui/tools/modes.js b/modules/ui/tools/modes.js index edaa8a7f34..91971f6f26 100644 --- a/modules/ui/tools/modes.js +++ b/modules/ui/tools/modes.js @@ -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)); diff --git a/modules/util/util.js b/modules/util/util.js index e370f3db50..b61637937d 100644 --- a/modules/util/util.js +++ b/modules/util/util.js @@ -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');