Skip to content

Commit 8185cc0

Browse files
committed
Clean up mouse-handling code and add support for Project#options.hitTolerance.
1 parent 80600d2 commit 8185cc0

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

src/ui/CanvasView.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
5858
}
5959
}, new function() { // Item based mouse handling:
6060

61-
var hitOptions = {
62-
fill: true,
63-
stroke: true,
64-
tolerance: 0
65-
};
66-
6761
var downPoint,
6862
lastPoint,
6963
overPoint,
@@ -97,18 +91,23 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
9791

9892
function handleEvent(view, type, event, point, lastPoint) {
9993
if (view._eventCounters[type]) {
100-
var hit = view._project.hitTest(point, hitOptions),
94+
var project = view._project,
95+
hit = project.hitTest(point, {
96+
tolerance: project.options.hitTolerance || 0,
97+
fill: true,
98+
stroke: true
99+
}),
101100
item = hit && hit.item;
102101
if (item) {
103102
// If this is a mousemove event and we change the overItem,
104103
// reset lastPoint to point so delta is (0, 0)
105-
if (type == 'mousemove' && item != overItem)
104+
if (type === 'mousemove' && item != overItem)
106105
lastPoint = point;
107106
// If we have a downItem with a mousedrag event, do not send
108107
// mousemove events to any item while we're dragging.
109108
// TODO: Do we also need to lock mousenter / mouseleave in the
110109
// same way?
111-
if (type != 'mousemove' || !hasDrag)
110+
if (type !== 'mousemove' || !hasDrag)
112111
callEvent(type, event, point, item, lastPoint);
113112
return item;
114113
}
@@ -143,7 +142,7 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
143142
callEvent('mousemove', event, point, item, overPoint);
144143
}
145144
}
146-
if (item == downItem) {
145+
if (item === downItem) {
147146
clickTime = Date.now();
148147
if (!doubleClick
149148
// callEvent returns false if event is stopped.
@@ -161,7 +160,7 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
161160
callEvent('mousedrag', event, point, downItem, lastPoint);
162161
var item = handleEvent(this, 'mousemove', event, point, overPoint);
163162
lastPoint = overPoint = point;
164-
if (item != overItem) {
163+
if (item !== overItem) {
165164
callEvent('mouseleave', event, point, overItem);
166165
overItem = item;
167166
callEvent('mouseenter', event, point, item);

0 commit comments

Comments
 (0)