Skip to content

Commit

Permalink
Fix disable dragPan after second click on feature
Browse files Browse the repository at this point in the history
Closes #1328
  • Loading branch information
underoot committed Jan 7, 2025
1 parent 42818a8 commit 4953db7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/modes/direct_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ DirectSelect.fireActionable = function(state) {
};

DirectSelect.startDragging = function(state, e) {
state.initialDragPanState = this.map.dragPan.isEnabled();
if (state.initialDragPanState == null) {
state.initialDragPanState = this.map.dragPan.isEnabled();
}

this.map.dragPan.disable();
state.canDragMove = true;
Expand All @@ -39,6 +41,8 @@ DirectSelect.stopDragging = function(state) {
if (state.canDragMove && state.initialDragPanState === true) {
this.map.dragPan.enable();
}

state.initialDragPanState = null;
state.dragMoving = false;
state.canDragMove = false;
state.dragMoveLocation = null;
Expand Down
27 changes: 27 additions & 0 deletions test/direct_select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,33 @@ test('direct_select', async (t) => {
}
});

await t.test('direct_select - double click should not disable enabled dragPan', async () => {
const ids = Draw.add(getGeoJSON('polygon'));

Draw.changeMode(Constants.modes.DIRECT_SELECT, {
featureId: ids[0]
});

await afterNextRender();

spy(map.dragPan, 'enable');
spy(map.dragPan, 'disable');


for (let i = 0; i < 2; i++) {
map.fire('mousedown', makeMouseEvent(35, 25));
await afterNextRender();
}

map.fire('mousemove', makeMouseEvent(0, 0));

assert.equal(map.dragPan.enable.callCount, 1, 'dragPan.enable called');

map.dragPan.enable.restore();
map.dragPan.disable.restore();
});


await t.test('direct_select - should fire correct actionable when no vertices selected', async () => {
const ids = Draw.add(getGeoJSON('polygon'));
Draw.changeMode(Constants.modes.SIMPLE_SELECT, {
Expand Down

0 comments on commit 4953db7

Please sign in to comment.