Skip to content

Commit 8b5e43d

Browse files
authored
fix: reset touch state when iPad Safari loses focus (#7134)
## Summary When the browser loses focus (e.g., switching apps, showing the dock), touchend events may not fire, causing touchCount to remain non-zero. This blocks all subsequent single-finger interactions since processMouseDown returns early when touchCount > 0. Added visibilitychange and touchcancel event listeners to reset touch state when the page becomes hidden or touch is interrupted by the system. fix #6721 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7134-fix-reset-touch-state-when-iPad-Safari-loses-focus-2be6d73d3650819abc7cf9c602909228) by [Unito](https://www.unito.io)
1 parent e9d5ce7 commit 8b5e43d

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/extensions/core/simpleTouchSupport.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { LGraphCanvas, LiteGraph } from '@/lib/litegraph/src/litegraph'
22

3-
import { app } from '../../scripts/app'
3+
import { app } from '@/scripts/app'
44

55
let touchZooming = false
66
let touchCount = 0
@@ -82,6 +82,26 @@ app.registerExtension({
8282
}
8383
)
8484

85+
const resetTouchState = () => {
86+
touchCount = 0
87+
touchZooming = false
88+
touchTime = null
89+
lastTouch = null
90+
lastScale = null
91+
touchDist = null
92+
}
93+
94+
// Reset touch state when page loses visibility (e.g., switching apps on iPad)
95+
// This prevents touchCount from getting stuck when touchend events are missed
96+
document.addEventListener('visibilitychange', () => {
97+
if (document.hidden) {
98+
resetTouchState()
99+
}
100+
})
101+
102+
// Also handle touchcancel which fires when touch is interrupted
103+
app.canvasEl.parentElement?.addEventListener('touchcancel', resetTouchState)
104+
85105
app.canvasEl.parentElement?.addEventListener(
86106
'touchmove',
87107
(e) => {

0 commit comments

Comments
 (0)