From 6223342890ba36096e3a9ea9b03a22ec0c3a17e0 Mon Sep 17 00:00:00 2001 From: Anish Athalye Date: Sat, 1 Jul 2017 16:27:49 -0700 Subject: [PATCH 1/2] Add scroll functionality for mobile --- src/Viewport.ts | 15 +++++++++++++++ src/xterm.js | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/Viewport.ts b/src/Viewport.ts index 82f748ea..6d4c1c84 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,18 @@ export class Viewport { // Prevent the page from scrolling when the terminal scrolls ev.preventDefault(); }; + + public onTouchStart(ev: TouchEvent) { + this.lastTouchY = ev.touches[0].pageY; + }; + + 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); + }); }; /** From 3e8ddd19664b505a6ab4c9dd8b7c8e554ccc34b7 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Mon, 3 Jul 2017 21:43:52 -0700 Subject: [PATCH 2/2] Add jsdoc --- src/Viewport.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Viewport.ts b/src/Viewport.ts index 6d4c1c84..5be6bffd 100644 --- a/src/Viewport.ts +++ b/src/Viewport.ts @@ -123,10 +123,18 @@ export class Viewport { 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;