fix(label-editing): complete editing operation on drag init

Make sure the direct editing results are applied (not discarded)
when the user starts a drag operation with direct editing active.

Closes #490
This commit is contained in:
Nico Rehwaldt 2016-03-08 14:41:32 +01:00
parent fa2254f0ef
commit 7ad9c7106e
2 changed files with 186 additions and 159 deletions

View File

@ -25,7 +25,7 @@ function LabelEditingProvider(eventBus, canvas, directEditing, commandStack) {
}); });
// complete on followup canvas operation // complete on followup canvas operation
eventBus.on([ 'element.mousedown', 'drag.activate', 'canvas.viewbox.changed' ], function(event) { eventBus.on([ 'element.mousedown', 'drag.init', 'canvas.viewbox.changed' ], function(event) {
directEditing.complete(); directEditing.complete();
}); });

View File

@ -6,7 +6,8 @@ require('../../../TestHelper');
var labelEditingModule = require('../../../../lib/features/label-editing'), var labelEditingModule = require('../../../../lib/features/label-editing'),
coreModule = require('../../../../lib/core'); coreModule = require('../../../../lib/core'),
draggingModule = require('diagram-js/lib/features/dragging');
var LabelUtil = require('../../../../lib/features/label-editing/LabelUtil'); var LabelUtil = require('../../../../lib/features/label-editing/LabelUtil');
@ -29,13 +30,14 @@ describe('features - label-editing', function() {
var diagramXML = require('../../../fixtures/bpmn/features/label-editing/labels.bpmn'); var diagramXML = require('../../../fixtures/bpmn/features/label-editing/labels.bpmn');
var testModules = [ labelEditingModule, coreModule ];
describe('basics', function() {
var testModules = [ labelEditingModule, coreModule, draggingModule ];
beforeEach(bootstrapViewer(diagramXML, { modules: testModules })); beforeEach(bootstrapViewer(diagramXML, { modules: testModules }));
describe('basics', function() {
it('should register on dblclick', inject(function(elementRegistry, directEditing, eventBus) { it('should register on dblclick', inject(function(elementRegistry, directEditing, eventBus) {
// given // given
@ -74,6 +76,24 @@ describe('features - label-editing', function() {
})); }));
it('should complete on drag start', inject(function(elementRegistry, directEditing, dragging) {
// given
var shape = elementRegistry.get('task-nested-embedded'),
task = shape.businessObject;
directEditing.activate(shape);
directEditing._textbox.textarea.value = 'FOO BAR';
// when
dragging.init(null, { x: 0, y: 0 }, 'foo');
// then
expect(task.name).to.equal('FOO BAR');
}));
it('should submit on root element click', inject(function(elementRegistry, directEditing, canvas, eventBus) { it('should submit on root element click', inject(function(elementRegistry, directEditing, canvas, eventBus) {
// given // given
@ -102,6 +122,12 @@ describe('features - label-editing', function() {
}); });
describe('details', function() {
var testModules = [ labelEditingModule, coreModule ];
beforeEach(bootstrapViewer(diagramXML, { modules: testModules }));
var elementRegistry, var elementRegistry,
eventBus, eventBus,
directEditing; directEditing;
@ -310,5 +336,6 @@ describe('features - label-editing', function() {
it('lane without label', directEdit('nested-lane-no-label')); it('lane without label', directEdit('nested-lane-no-label'));
}); });
});
}); });