mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Merge pull request #747 from anishathalye/master
Add scroll functionality for mobile
This commit is contained in:
@@ -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();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user