Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix double click #253

Merged
merged 2 commits into from
Jul 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@
this._setPointerPosition(evt);
var shape = this.getIntersection(this.getPointerPosition()),
clickStartShape = this.clickStartShape,
clickEndShape = this.clickEndShape,
fireDblClick = false,
dd = Konva.DD;

Expand All @@ -547,6 +548,7 @@
}, Konva.dblClickWindow);

if (shape && shape.isListening()) {
this.clickEndShape = shape;
shape._fireAndBubble(MOUSEUP, { evt: evt });

// detect if click or double click occurred
Expand All @@ -557,7 +559,11 @@
) {
shape._fireAndBubble(CLICK, { evt: evt });

if (fireDblClick) {
if (
fireDblClick &&
clickEndShape &&
clickEndShape._id === shape._id
) {
shape._fireAndBubble(DBL_CLICK, { evt: evt });
}
}
Expand Down
66 changes: 66 additions & 0 deletions test/functional/MouseEvents-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,72 @@ suite('MouseEvents', function() {
);
});

// ======================================================
test('test dblclick to a wrong target', function () {
var stage = addStage();
var layer = new Konva.Layer();
stage.add(layer);

var leftRect = new Konva.Rect({
x: 0,
y: 0,
width: 100,
height: 100,
fill: 'red'
});
layer.add(leftRect);

var rightRect = new Konva.Rect({
x: 100,
y: 0,
width: 100,
height: 100,
fill: 'blue'
});
layer.add(rightRect);

stage.draw();

var leftRectSingleClick = 0;
var rightRectSingleClick = 0;
var rightRectDblClick = 0;

leftRect.on('click', function () {
leftRectSingleClick++;
});
rightRect.on('click', function () {
rightRectSingleClick++;
});
rightRect.on('dblclick', function () {
rightRectDblClick++;
});

stage.simulateMouseDown({
x: 50,
y: 50
});
stage.simulateMouseUp({
x: 50,
y: 50
});
assert.equal(leftRectSingleClick, 1, 'leftRect trigger a click');

stage.simulateMouseDown({
x: 150,
y: 50
});
stage.simulateMouseUp({
x: 150,
y: 50
});
assert.equal(rightRectSingleClick, 1, 'rightRect trigger a click');
assert.equal(
rightRectDblClick,
0,
'rightRect dblClick should not trigger'
);
});

// ======================================================
test('test mouseleave + mouseenter with deep nesting', function() {
var stage = addStage();
Expand Down