diff --git a/src/Viewport.ts b/src/Viewport.ts index 82f748ea..5be6bffd 100644 --- a/src/Viewport.ts +++ b/src/Viewport.ts @@ -13,6 +13,7 @@ export class Viewport { private currentRowHeight: number; private lastRecordedBufferLength: number; private lastRecordedViewportHeight: number; + private lastTouchY: number; /** * Creates a new Viewport. @@ -121,4 +122,26 @@ export class Viewport { // Prevent the page from scrolling when the terminal scrolls ev.preventDefault(); }; + + /** + * Handles the touchstart event, recording the touch occurred. + * @param ev The touch event. + */ + public onTouchStart(ev: TouchEvent) { + this.lastTouchY = ev.touches[0].pageY; + }; + + /** + * Handles the touchmove event, scrolling the viewport if the position shifted. + * @param ev The touch event. + */ + public onTouchMove(ev: TouchEvent) { + let deltaY = this.lastTouchY - ev.touches[0].pageY; + this.lastTouchY = ev.touches[0].pageY; + if (deltaY === 0) { + return; + } + this.viewportElement.scrollTop += deltaY; + ev.preventDefault(); + }; } diff --git a/src/xterm.js b/src/xterm.js index a8a76fb9..dc3b940b 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -1095,6 +1095,18 @@ Terminal.prototype.bindMouse = function() { self.viewport.onWheel(ev); return self.cancel(ev); }); + + on(el, 'touchstart', function(ev) { + if (self.mouseEvents) return; + self.viewport.onTouchStart(ev); + return self.cancel(ev); + }); + + on(el, 'touchmove', function(ev) { + if (self.mouseEvents) return; + self.viewport.onTouchMove(ev); + return self.cancel(ev); + }); }; /**