revert: remove JS touch scroll handlers — back to mouse-only baseline
Removing terminal WheelEvent dispatch and sidebar scrollTop handlers. CSS fixes retained (touch-action:pan-y, overscroll-behavior:contain, flex-shrink:0). Testing mouse-only baseline across all devices before deciding on the right mobile scroll approach.
This commit is contained in:
@@ -247,53 +247,4 @@ function closeTerminal() {
|
||||
window._openTerminal = openTerminal;
|
||||
window._closeTerminal = closeTerminal;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Touch scroll — accumulates delta and dispatches fixed-size WheelEvents.
|
||||
// Fixed deltaY=120 per SCROLL_PX pixels ensures consistent scroll steps
|
||||
// regardless of how Android Chrome batches touchmove events. Each WheelEvent
|
||||
// travels through xterm.js mouse reporting to tmux (the "inside" path).
|
||||
// Mouse wheel (wheel event) and iOS/desktop are unaffected.
|
||||
// ---------------------------------------------------------------------------
|
||||
;(function initTerminalTouchScroll() {
|
||||
var container = document.getElementById('terminal-container');
|
||||
if (!container || typeof container.addEventListener !== 'function') return;
|
||||
|
||||
var _touchLastY = 0;
|
||||
var _accumulated = 0; // running pixel debt between scroll events
|
||||
var SCROLL_PX = 20; // pixels of touch movement = one scroll click
|
||||
|
||||
container.addEventListener('touchstart', function (e) {
|
||||
_touchLastY = e.touches[0].clientY;
|
||||
_accumulated = 0; // reset on new touch
|
||||
}, { passive: true });
|
||||
|
||||
container.addEventListener('touchmove', function (e) {
|
||||
if (!_term) return;
|
||||
e.preventDefault();
|
||||
|
||||
var y = e.touches[0].clientY;
|
||||
_accumulated += _touchLastY - y; // accumulate — positive = swipe up
|
||||
_touchLastY = y;
|
||||
|
||||
var viewport = container.querySelector('.xterm-viewport');
|
||||
if (!viewport) return;
|
||||
|
||||
// Fire one standard-sized click (deltaY=120) per SCROLL_PX pixels.
|
||||
// Fixed deltaY makes every step identical regardless of Android event batching.
|
||||
while (Math.abs(_accumulated) >= SCROLL_PX) {
|
||||
var dir = _accumulated > 0 ? 1 : -1;
|
||||
viewport.dispatchEvent(new WheelEvent('wheel', {
|
||||
deltaY: dir * 120, // 120 = one standard wheel click, consistent
|
||||
deltaMode: WheelEvent.DOM_DELTA_PIXEL,
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}));
|
||||
_accumulated -= dir * SCROLL_PX;
|
||||
}
|
||||
}, { passive: false }); // passive: false required to allow e.preventDefault()
|
||||
|
||||
container.addEventListener('touchend', function () {
|
||||
_touchLastY = 0;
|
||||
_accumulated = 0; // discard sub-threshold remainder on lift
|
||||
}, { passive: true });
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user