Skip to content

Commit 15df388

Browse files
author
HarshKhandeparkar
committed
fix<RealDrawBoard>: mouseLeave
event listeners fixed
1 parent 936b09b commit 15df388

File tree

5 files changed

+7
-16
lines changed

5 files changed

+7
-16
lines changed

dist/gpujs-real-renderer-browser.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,6 @@
11171117
function _addDOMEvents() {
11181118
this.canvas.addEventListener('mousedown', this._mouseDownEventListener);
11191119
this.canvas.addEventListener('mouseup', this._mouseUpEventListener);
1120-
this.canvas.addEventListener('mouseenter', this._mouseEnterEventListener);
11211120
this.canvas.addEventListener('mouseleave', this._mouseLeaveEventListener);
11221121
this.canvas.addEventListener('touchstart', this._touchStartEventListener);
11231122
this.canvas.addEventListener('touchmove', this._touchMoveEventListener);
@@ -1127,7 +1126,6 @@
11271126
function _removeDOMEvents() {
11281127
this.canvas.removeEventListener('mousedown', this._mouseDownEventListener);
11291128
this.canvas.removeEventListener('mouseup', this._mouseUpEventListener);
1130-
this.canvas.removeEventListener('mouseenter', this._mouseEnterEventListener);
11311129
this.canvas.removeEventListener('mouseexit', this._mouseLeaveEventListener);
11321130
this.canvas.removeEventListener('touchstart', this._touchStartEventListener);
11331131
this.canvas.removeEventListener('touchmove', this._touchMoveEventListener);
@@ -1161,7 +1159,8 @@
11611159
if (this._lastCoords.get(identifier)[0] === endCoords[0] &&
11621160
this._lastCoords.get(identifier)[1] === endCoords[1]) {
11631161
this._plot.apply(this, endCoords);
1164-
this._drawnPaths[this._pathIndex + 1].pathCoords.push(__spreadArrays(endCoords, [true]));
1162+
if (this._drawnPaths[this._pathIndex + 1])
1163+
this._drawnPaths[this._pathIndex + 1].pathCoords.push(__spreadArrays(endCoords, [true]));
11651164
}
11661165
this._lastCoords.delete(identifier);
11671166
if (this._drawnPaths[this._pathIndex + 1].pathCoords.length === 0)
@@ -1296,12 +1295,10 @@
12961295
_this.canvas.removeEventListener('mousemove', _this._mouseMoveEventListener);
12971296
}
12981297
};
1299-
_this._mouseEnterEventListener = function (e) {
1300-
_this._lastCoords.set('mouse', _this._getMouseCoords(e));
1301-
};
13021298
_this._mouseLeaveEventListener = function (e) {
13031299
_this.canvas.removeEventListener('mousemove', _this._mouseMoveEventListener);
1304-
_this._endStroke(_this._getMouseCoords(e), 'mouse');
1300+
if (_this._lastCoords.has('mouse'))
1301+
_this._endStroke(_this._getMouseCoords(e), 'mouse');
13051302
};
13061303
_this._mouseMoveEventListener = function (e) {
13071304
var coords = _this._getMouseCoords(e);

dist/gpujs-real-renderer-browser.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderers/RealDrawBoard/RealDrawBoard.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,9 @@ export class RealDrawBoard extends RealRenderer {
121121
}
122122
}
123123

124-
_mouseEnterEventListener = (e: MouseEvent) => {
125-
this._lastCoords.set('mouse', this._getMouseCoords(e));
126-
}
127-
128124
_mouseLeaveEventListener = (e: MouseEvent) => {
129125
this.canvas.removeEventListener('mousemove', this._mouseMoveEventListener);
130-
this._endStroke(this._getMouseCoords(e), 'mouse');
126+
if(this._lastCoords.has('mouse')) this._endStroke(this._getMouseCoords(e), 'mouse');
131127
}
132128

133129
_mouseMoveEventListener = (e: MouseEvent) => {

src/renderers/RealDrawBoard/_DOMEvents.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { RealDrawBoard } from './RealDrawBoard';
33
export function _addDOMEvents(this: RealDrawBoard) {
44
this.canvas.addEventListener('mousedown', this._mouseDownEventListener);
55
this.canvas.addEventListener('mouseup', this._mouseUpEventListener);
6-
this.canvas.addEventListener('mouseenter', this._mouseEnterEventListener);
76
this.canvas.addEventListener('mouseleave', this._mouseLeaveEventListener);
87

98
this.canvas.addEventListener('touchstart', this._touchStartEventListener);
@@ -14,7 +13,6 @@ export function _addDOMEvents(this: RealDrawBoard) {
1413
export function _removeDOMEvents(this: RealDrawBoard) {
1514
this.canvas.removeEventListener('mousedown', this._mouseDownEventListener);
1615
this.canvas.removeEventListener('mouseup', this._mouseUpEventListener);
17-
this.canvas.removeEventListener('mouseenter', this._mouseEnterEventListener);
1816
this.canvas.removeEventListener('mouseexit', this._mouseLeaveEventListener);
1917

2018
this.canvas.removeEventListener('touchstart', this._touchStartEventListener);

src/renderers/RealDrawBoard/stroke.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function _endStroke(
2727
this._lastCoords.get(identifier)[1] === endCoords[1]
2828
) {
2929
this._plot(...endCoords);
30-
this._drawnPaths[this._pathIndex + 1].pathCoords.push([...endCoords, true]);
30+
if(this._drawnPaths[this._pathIndex + 1]) this._drawnPaths[this._pathIndex + 1].pathCoords.push([...endCoords, true]);
3131
}
3232

3333
this._lastCoords.delete(identifier);

0 commit comments

Comments
 (0)