remove scrolling sum

This commit is contained in:
hippoz 2021-10-29 13:49:59 +03:00
parent 248216891b
commit 23eddd1206
No known key found for this signature in database
GPG key ID: 7C52899193467641

View file

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