remove scrolling sum

This commit is contained in:
hippoz 2021-10-29 13:49:59 +03:00
parent 248216891b
commit 23eddd1206
Signed by: hippoz
GPG key ID: 7C52899193467641

View file

@ -156,14 +156,15 @@
element.addEventListener("touchstart", this.onTouchStart.bind(this)); element.addEventListener("touchstart", this.onTouchStart.bind(this));
} }
onTouchMove({ touches }) { onTouchMove({ preventDefault, touches }) {
preventDefault();
for (let i = 0; i < touches.length; i++) { for (let i = 0; i < touches.length; i++) {
this.ongoingTouches[touches[i].identifier].hasMoved = true; this.ongoingTouches[touches[i].identifier].hasMoved = true;
} }
const targetTouch = touches[0]; const targetTouch = touches[0];
this.currentMoveX = targetTouch.clientX; this.currentMoveX = targetTouch.pageX;
this.currentMoveY = targetTouch.clientY; this.currentMoveY = targetTouch.pageY;
// When ending a touch and starting a new one in another part of the touchpad, // When ending a touch and starting a new one in another part of the touchpad,
// the cursor "rubber bands" to that position. // the cursor "rubber bands" to that position.
// To solve this, the "last move" parameters are reset when a touch is ended // To solve this, the "last move" parameters are reset when a touch is ended
@ -179,22 +180,14 @@
this.lastMoveY = this.currentMoveY; this.lastMoveY = this.currentMoveY;
// if two touches moved at the same time, assume scrolling intent // if two touches moved at the same time, assume scrolling intent
if (touches.length === 2) { if (touches.length === 2) {
this.scrollXSum += 1; this._sendRelativeMouseScroll(deltaX, deltaY);
this.scrollYSum += 1;
if (this.scrollXSum > SCROLL_X_THRESHOLD) {
this._sendRelativeMouseScroll(deltaX, 0);
this.scrollXSum = 0;
}
if (this.scrollYSum > SCROLL_Y_THRESHOLD) {
this._sendRelativeMouseScroll(0, deltaY);
this.scrollYSum = 0;
}
} else { } else {
this._sendRelativeMouseMovement(deltaX, deltaY); this._sendRelativeMouseMovement(deltaX, deltaY);
} }
} }
onTouchEnd({ changedTouches }) { onTouchEnd({ preventDefault, changedTouches }) {
preventDefault();
this.shouldResetLastMove = true; this.shouldResetLastMove = true;
if (changedTouches.length === 1) { if (changedTouches.length === 1) {
// This is a single tap - left click // This is a single tap - left click
@ -214,7 +207,9 @@
} }
} }
onTouchStart({ changedTouches }) { onTouchStart({ preventDefault, changedTouches }) {
preventDefault();
// Clear the hold mode time out if another touch begins // Clear the hold mode time out if another touch begins
if (this.holdModeTimeout) if (this.holdModeTimeout)
clearTimeout(this.holdModeTimeout); clearTimeout(this.holdModeTimeout);