diff --git a/lib/features/label-editing/LabelEditingProvider.js b/lib/features/label-editing/LabelEditingProvider.js index c07ad8ce..364f2713 100644 --- a/lib/features/label-editing/LabelEditingProvider.js +++ b/lib/features/label-editing/LabelEditingProvider.js @@ -26,37 +26,40 @@ function LabelEditingProvider(eventBus, canvas, directEditing, commandStack, inj directEditing.activate(event.element); }); - // intercept direct canvas clicks to deselect all selected shapes - eventBus.on('element.click', function(event) { + // complete on followup canvas operation + eventBus.on([ 'element.mousedown', 'drag.activate', 'canvas.viewbox.changed' ], function(event) { directEditing.complete(); }); - eventBus.on('canvas.viewbox.changed', function(event) { - directEditing.complete(); + // cancel on command stack changes + eventBus.on([ 'commandStack.changed' ], function() { + directEditing.cancel(); }); - // remove and restore selection during direct editing - (function() { + // activate direct editing for activities and text annotations - try { - var selection = injector.get('selection'); - var localSelection; + if ('ontouchstart' in document.documentElement) { + // we deactivate automatic label editing on mobile devices + // as it breaks the user interaction workflow - eventBus.on('directEditing.activate', function() { - localSelection = selection.get(); - selection.select(null); - }); + // TODO(nre): we should temporarily focus the edited element here + // and release the focused viewport after the direct edit operation is finished + } else { + eventBus.on('create.end', 500, function(e) { - eventBus.on('directEditing.deactivate', function() { - selection.select(localSelection); - localSelection = null; - }); - } catch (e) { } + var element = e.shape, + businessObject = element.businessObject; - })(); + if (businessObject.$instanceOf('bpmn:Task') || + businessObject.$instanceOf('bpmn:TextAnnotation') || + (businessObject.$instanceOf('bpmn:SubProcess') && !businessObject.di.isExpanded)) { + directEditing.activate(element); + } + }); + } this._canvas = canvas; this._commandStack = commandStack; diff --git a/test/spec/features/label-editing/LabelEditingProviderSpec.js b/test/spec/features/label-editing/LabelEditingProviderSpec.js index 0275be73..7b8336f3 100644 --- a/test/spec/features/label-editing/LabelEditingProviderSpec.js +++ b/test/spec/features/label-editing/LabelEditingProviderSpec.js @@ -84,9 +84,9 @@ describe('features - label-editing', function() { var textarea = directEditing._textbox.textarea; // when - // change + + // change + textarea.val(newName); - eventBus.fire('element.click', { element: canvas.getRootElement() }); + eventBus.fire('element.mousedown', { element: canvas.getRootElement() }); // then expect(directEditing.isActive()).toBe(false);