Skip to content

Commit 08aebb8

Browse files
authored
Refactor touch and click event handling
1 parent 46aee27 commit 08aebb8

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

editor.html

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,9 +2924,7 @@ <h3 style="margin-top:0;">Loading Project</h3>
29242924
let cinematicRevealCleanup = null;
29252925
let playerCinematicEnabled = false;
29262926
2927-
const isTouchDevice = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
29282927
const isAndroid = /android/i.test(navigator.userAgent);
2929-
const clickEvent = isTouchDevice ? 'touchend' : 'click';
29302928
const VIDEO_EXTENSIONS = ['.mp4', '.webm', '.ogv'];
29312929
const isVideo = (path) => {
29322930
if (!path) return false;
@@ -2959,8 +2957,13 @@ <h3 style="margin-top:0;">Loading Project</h3>
29592957
29602958
function bindEvent(element, handler) {
29612959
if(!element) return;
2962-
element.addEventListener(clickEvent, (e) => {
2963-
if (isTouchDevice) e.preventDefault();
2960+
// 1. Handle standard mouse/trackpad clicks
2961+
element.addEventListener('click', (e) => {
2962+
handler(e);
2963+
});
2964+
// 2. Handle fast touch events
2965+
element.addEventListener('touchend', (e) => {
2966+
if (e.cancelable) e.preventDefault(); // Prevent touch from generating a "ghost click"
29642967
handler(e);
29652968
});
29662969
}
@@ -3164,10 +3167,15 @@ <h3 style="margin-top:0;">Loading Project</h3>
31643167
contentContainer.style.minHeight = originalMinHeight;
31653168
};
31663169
3167-
const clickHandler = (e) => { if (!isTouchDevice) skip(e); };
3170+
const clickHandler = (e) => { skip(e); };
31683171
const touchStartHandler = () => { isScrolling = false; };
31693172
const touchMoveHandler = () => { isScrolling = true; };
3170-
const touchEndHandler = (e) => { if (!isScrolling) skip(e); };
3173+
const touchEndHandler = (e) => {
3174+
if (!isScrolling) {
3175+
if (e.cancelable) e.preventDefault(); // Prevent ghost click
3176+
skip(e);
3177+
}
3178+
};
31713179
31723180
gameContainer.addEventListener('click', clickHandler);
31733181
gameContainer.addEventListener('touchstart', touchStartHandler, { passive: true });
@@ -3555,7 +3563,6 @@ <h3 style="margin-top:0;">Loading Project</h3>
35553563
App.ui.showNotification("Could not export project. Check console for details.");
35563564
});
35573565
},
3558-
35593566
async previewProject() {
35603567
if (!App.state.projectDirectoryHandle) { App.ui.showNotification("Please open a project to preview."); return; }
35613568
App.editor.saveCurrentScene();
@@ -6617,3 +6624,4 @@ <h3 style="margin-top:0;">Loading Project</h3>
66176624
</script>
66186625
</body>
66196626
</html>
6627+

0 commit comments

Comments
 (0)