Fix touch scrolling: dispatch arrow key events to xterm textarea
WheelEvent approach didn't work. Now dispatches ArrowUp/ArrowDown KeyboardEvents to the xterm helper textarea, which xterm forwards to the Textual app as actual key presses. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -164,35 +164,43 @@
|
|||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// Touch-to-scroll: translate swipe gestures into wheel events for xterm
|
// Touch-to-scroll: translate swipe gestures into key events for Textual
|
||||||
(function() {
|
(function() {
|
||||||
var touchStartY = null;
|
var touchStartY = null;
|
||||||
var THRESHOLD = 5;
|
var accumDY = 0;
|
||||||
|
var STEP = 20; // pixels per scroll step
|
||||||
|
|
||||||
document.addEventListener("touchstart", function(e) {
|
document.addEventListener("touchstart", function(e) {
|
||||||
if (e.touches.length === 1) {
|
if (e.touches.length === 1) {
|
||||||
touchStartY = e.touches[0].clientY;
|
touchStartY = e.touches[0].clientY;
|
||||||
|
accumDY = 0;
|
||||||
}
|
}
|
||||||
}, { passive: true });
|
}, { passive: true });
|
||||||
|
|
||||||
document.addEventListener("touchmove", function(e) {
|
document.addEventListener("touchmove", function(e) {
|
||||||
if (touchStartY === null || e.touches.length !== 1) return;
|
if (touchStartY === null || e.touches.length !== 1) return;
|
||||||
var dy = touchStartY - e.touches[0].clientY;
|
e.preventDefault();
|
||||||
if (Math.abs(dy) < THRESHOLD) return;
|
|
||||||
touchStartY = e.touches[0].clientY;
|
|
||||||
|
|
||||||
var target = document.querySelector(".xterm-screen") || document.querySelector("#terminal");
|
var currentY = e.touches[0].clientY;
|
||||||
if (!target) return;
|
accumDY += touchStartY - currentY;
|
||||||
target.dispatchEvent(new WheelEvent("wheel", {
|
touchStartY = currentY;
|
||||||
deltaY: dy > 0 ? 3 : -3,
|
|
||||||
deltaMode: 0,
|
var textarea = document.querySelector(".xterm-helper-textarea");
|
||||||
bubbles: true,
|
if (!textarea) return;
|
||||||
cancelable: true
|
|
||||||
}));
|
while (Math.abs(accumDY) >= STEP) {
|
||||||
|
var key = accumDY > 0 ? "ArrowDown" : "ArrowUp";
|
||||||
|
textarea.dispatchEvent(new KeyboardEvent("keydown", {
|
||||||
|
key: key, code: key, keyCode: key === "ArrowDown" ? 40 : 38,
|
||||||
|
bubbles: true, cancelable: true
|
||||||
|
}));
|
||||||
|
accumDY -= (accumDY > 0 ? STEP : -STEP);
|
||||||
|
}
|
||||||
}, { passive: false });
|
}, { passive: false });
|
||||||
|
|
||||||
document.addEventListener("touchend", function() {
|
document.addEventListener("touchend", function() {
|
||||||
touchStartY = null;
|
touchStartY = null;
|
||||||
|
accumDY = 0;
|
||||||
}, { passive: true });
|
}, { passive: true });
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user