Skip to content

Commit 0fa93e8

Browse files
committed
Better event handling
1 parent 498f8ef commit 0fa93e8

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

js/block.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2883,6 +2883,11 @@ class Block {
28832883
* @param {Event} event - The mousedown event.
28842884
*/
28852885
this.container.on("mousedown", (event) =>{
2886+
if (event.nativeEvent) {
2887+
event.nativeEvent.preventDefault();
2888+
}
2889+
event.stopPropagation();
2890+
28862891
docById("contextWheelDiv").style.display = "none";
28872892

28882893
// Track time for detecting long pause...
@@ -2926,7 +2931,11 @@ class Block {
29262931
*/
29272932
this.container.on("pressmove", (event) =>{
29282933
// FIXME: More voodoo
2929-
event.nativeEvent.preventDefault();
2934+
if (event.nativeEvent) {
2935+
event.nativeEvent.preventDefault();
2936+
} else {
2937+
event.preventDefault();
2938+
}
29302939

29312940
// Don't allow silence block to be dragged out of a note.
29322941
if (that.name === "rest2") {
@@ -3079,13 +3088,25 @@ class Block {
30793088
});
30803089

30813090
this.container.on("touchstart", (event) => {
3082-
event.preventDefault();
3083-
event.stopPropagation();
3084-
that.blocks.mouseDownTime = new Date().getTime();
3085-
that.blocks.longPressTimeout = setTimeout(() => {
3086-
that.blocks.activeBlock = that.blocks.blockList.indexOf(that);
3087-
piemenuBlockContext(that);
3088-
}, LONGPRESSTIME);
3091+
if (event.touches.length === 1) {
3092+
event.preventDefault();
3093+
event.stopPropagation();
3094+
3095+
const touch = event.touches[0];
3096+
const mouseEvent = new MouseEvent('mousedown', {
3097+
clientX: touch.clientX,
3098+
clientY: touch.clientY,
3099+
screenX: touch.screenX,
3100+
screenY: touch.screenY
3101+
});
3102+
this.container.dispatchEvent(mouseEvent);
3103+
3104+
that.blocks.mouseDownTime = new Date().getTime();
3105+
that.blocks.longPressTimeout = setTimeout(() => {
3106+
that.blocks.activeBlock = that.blocks.blockList.indexOf(that);
3107+
piemenuBlockContext(that);
3108+
}, LONGPRESSTIME);
3109+
}
30893110
}, { passive: false });
30903111

30913112
this.container.on("touchstart", (event) => {

0 commit comments

Comments
 (0)