Merge pull request #13219 from ahocevar/modify-delete-no-event

Do not fire modifyend event when nothing was modified
This commit is contained in:
Andreas Hocevar
2022-01-11 13:56:08 +01:00
committed by GitHub
2 changed files with 42 additions and 8 deletions
+10 -7
View File
@@ -1360,13 +1360,16 @@ class Modify extends PointerInteraction {
const evt = this.lastPointerEvent_; const evt = this.lastPointerEvent_;
this.willModifyFeatures_(evt, this.dragSegments_); this.willModifyFeatures_(evt, this.dragSegments_);
const removed = this.removeVertex_(); const removed = this.removeVertex_();
this.dispatchEvent( if (this.featuresBeingModified_) {
new ModifyEvent( this.dispatchEvent(
ModifyEventType.MODIFYEND, new ModifyEvent(
this.featuresBeingModified_, ModifyEventType.MODIFYEND,
evt this.featuresBeingModified_,
) evt
); )
);
}
this.featuresBeingModified_ = null; this.featuresBeingModified_ = null;
return removed; return removed;
} }
@@ -20,7 +20,11 @@ import {
clearUserProjection, clearUserProjection,
setUserProjection, setUserProjection,
} from '../../../../../src/ol/proj.js'; } from '../../../../../src/ol/proj.js';
import {doubleClick, never} from '../../../../../src/ol/events/condition.js'; import {
click,
doubleClick,
never,
} from '../../../../../src/ol/events/condition.js';
import {getValues} from '../../../../../src/ol/obj.js'; import {getValues} from '../../../../../src/ol/obj.js';
describe('ol.interaction.Modify', function () { describe('ol.interaction.Modify', function () {
@@ -880,6 +884,33 @@ describe('ol.interaction.Modify', function () {
done(); done();
}, 0); }, 0);
}); });
it('does not fire `modifyend` when nothing is modified', function (done) {
const modify = new Modify({
features: new Collection(features),
deleteCondition: click,
insertVertexCondition: never,
});
map.addInteraction(modify);
let modifyend = false;
modify.on('modifyend', function (e) {
modifyend = true;
});
// try to add vertex
simulateEvent('pointermove', 40, -20, null, 0);
simulateEvent('pointerdown', 40, -20, null, 0);
simulateEvent('pointerdrag', 42, -30, null, 0);
simulateEvent('pointerup', 42, -30, null, 0);
simulateEvent('click', 42, -30, null, 0);
simulateEvent('singleclick', 42, -30, null, 0);
setTimeout(function () {
expect(modifyend).to.be(false);
done();
}, 0);
});
}); });
describe('handle feature change', function () { describe('handle feature change', function () {