mirror of
https://github.com/Pomax/BezierInfo-2.git
synced 2025-09-29 01:29:03 +02:00
bug fix on the event cancellation, which was causing scroll jumps and input-change cancellation
This commit is contained in:
@@ -88,6 +88,13 @@ class BaseAPI {
|
||||
);
|
||||
}
|
||||
|
||||
stopEvent(evt) {
|
||||
if (evt.target === this.canvas) {
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -116,7 +123,7 @@ class BaseAPI {
|
||||
*
|
||||
*/
|
||||
onMouseDown(evt) {
|
||||
stop(evt);
|
||||
this.stopEvent(evt);
|
||||
this.cursor.down = true;
|
||||
this.getCursorCoords(evt);
|
||||
}
|
||||
@@ -125,7 +132,7 @@ class BaseAPI {
|
||||
*
|
||||
*/
|
||||
onMouseMove(evt) {
|
||||
stop(evt);
|
||||
this.stopEvent(evt);
|
||||
this.cursor.move = true;
|
||||
this.getCursorCoords(evt);
|
||||
}
|
||||
@@ -134,7 +141,7 @@ class BaseAPI {
|
||||
*
|
||||
*/
|
||||
onMouseUp(evt) {
|
||||
stop(evt);
|
||||
this.stopEvent(evt);
|
||||
this.cursor.down = false;
|
||||
this.cursor.move = false;
|
||||
this.getCursorCoords(evt);
|
||||
@@ -148,7 +155,7 @@ class BaseAPI {
|
||||
// going to allow unmodified keys, or shift-modified keys,
|
||||
// and tab has to always work. For obvious reasons.
|
||||
if (!evt.altKey && !evt.ctrlKey && !evt.metaKey && evt.key !== "Tab") {
|
||||
stop(evt);
|
||||
this.stopEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,6 +191,7 @@ class BaseAPI {
|
||||
canvas.setAttribute(`tabIndex`, 0);
|
||||
canvas.classList.add(`focus-enabled`);
|
||||
canvas._force_listener = () => {
|
||||
/*
|
||||
// I have NO idea why forceFocus() causes a scroll, but
|
||||
// I don't have time to dig into what is no doubt deep
|
||||
// black spec magic, so: check where we are, force the
|
||||
@@ -194,8 +202,11 @@ class BaseAPI {
|
||||
// Oh yeah... using round() because apparently scrollTo
|
||||
// is not NOT idempotent and rounding errors cause it to
|
||||
// drift. IT'S FUCKING HILARIOUS
|
||||
*/
|
||||
this.forceFocus();
|
||||
/*
|
||||
window.scrollTo(x, y);
|
||||
*/
|
||||
};
|
||||
[`touchstart`, `mousedown`].forEach((evtName) =>
|
||||
canvas.addEventListener(evtName, canvas._force_listener)
|
||||
@@ -286,10 +297,4 @@ function enhanceContext(ctx) {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
// Outright kill off an event.
|
||||
function stop(evt) {
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation();
|
||||
}
|
||||
|
||||
export { BaseAPI };
|
||||
|
Reference in New Issue
Block a user