Skip to content

Commit 295991d

Browse files
Remote Agentclaude
andcommitted
fix: improve xterm mobile touch scrolling and readability
Add custom touch event handlers for smoother scroll on mobile devices, increase font size for touch screens, enable smooth scroll animation, and add CSS for iOS momentum scrolling. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 61d30b6 commit 295991d

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

packages/ui/src/hooks/useTerminal.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,19 @@ export function useTerminal(options: UseTerminalOptions): UseTerminalReturn {
121121
if (isDisposed) return;
122122

123123
// Initialize xterm with macOS Terminal-like appearance
124+
const isMobile = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
125+
124126
xterm = new Terminal({
125127
cursorBlink: true,
126128
cursorStyle: 'block',
127-
fontSize: 11,
129+
fontSize: isMobile ? 13 : 11,
128130
fontFamily: '"Fira Code", "SF Mono", "Menlo", "Monaco", "Cascadia Code", "Consolas", monospace',
129131
fontWeight: '500',
130132
fontWeightBold: '600',
131133
lineHeight: 1.2,
132134
letterSpacing: 0,
135+
scrollback: 5000,
136+
smoothScrollDuration: isMobile ? 100 : 0,
133137
allowTransparency: false,
134138
theme: {
135139
background: '#1e1e1e',
@@ -244,9 +248,38 @@ export function useTerminal(options: UseTerminalOptions): UseTerminalReturn {
244248

245249
container.addEventListener('paste', handlePaste);
246250
container.addEventListener('contextmenu', handleContextMenu);
251+
252+
// Improve mobile touch scrolling: boost scroll speed and momentum
253+
let touchStartY = 0;
254+
let touchScrollCleanup: (() => void) | null = null;
255+
if (isMobile) {
256+
const handleTouchStart = (e: TouchEvent) => {
257+
touchStartY = e.touches[0].clientY;
258+
};
259+
const handleTouchMove = (e: TouchEvent) => {
260+
if (!xterm) return;
261+
const deltaY = touchStartY - e.touches[0].clientY;
262+
touchStartY = e.touches[0].clientY;
263+
// Scroll by lines based on touch delta (amplify for momentum feel)
264+
const lines = Math.round(deltaY / 10);
265+
if (lines !== 0) {
266+
xterm.scrollLines(lines);
267+
}
268+
// Prevent page scroll while scrolling terminal
269+
e.preventDefault();
270+
};
271+
container.addEventListener('touchstart', handleTouchStart, { passive: true });
272+
container.addEventListener('touchmove', handleTouchMove, { passive: false });
273+
touchScrollCleanup = () => {
274+
container.removeEventListener('touchstart', handleTouchStart);
275+
container.removeEventListener('touchmove', handleTouchMove);
276+
};
277+
}
278+
247279
pasteCleanup = () => {
248280
container.removeEventListener('paste', handlePaste);
249281
container.removeEventListener('contextmenu', handleContextMenu);
282+
touchScrollCleanup?.();
250283
};
251284

252285
xtermRef.current = xterm;

packages/ui/src/index.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@
7777
background: linear-gradient(180deg, hsl(var(--card)) 0%, hsl(var(--background)) 100%);
7878
}
7979

80+
/* Improve xterm touch scrolling on mobile */
81+
@media (pointer: coarse) {
82+
.xterm .xterm-viewport {
83+
-webkit-overflow-scrolling: touch;
84+
overflow-y: auto !important;
85+
}
86+
.xterm .xterm-screen {
87+
touch-action: pan-y;
88+
}
89+
}
90+
8091
/* Git diff view enhancements */
8192
.diff-view-container {
8293
--diff-add-bg: rgba(46, 160, 67, 0.15);

0 commit comments

Comments
 (0)