Skip to content
This repository was archived by the owner on Oct 22, 2021. It is now read-only.

Commit 961412e

Browse files
committed
Closed #92: Terminal scrolling (touch and mouse)
FINALLY it's starting to get usable
1 parent 7814e3c commit 961412e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/classes/terminal.class.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,29 @@ class Terminal {
9999
};
100100
this.socket.onerror = (e) => {throw e};
101101

102+
let parent = document.getElementById(opts.parentId);
103+
parent.addEventListener("wheel", e => {
104+
this.term.scrollLines(Math.round(e.deltaY/10));
105+
});
106+
this._lastTouchY = null;
107+
parent.addEventListener("touchstart", e => {
108+
this._lastTouchY = e.targetTouches[0].screenY;
109+
});
110+
parent.addEventListener("touchmove", e => {
111+
if (this._lastTouchY) {
112+
let y = e.changedTouches[0].screenY;
113+
let deltaY = y - this._lastTouchY;
114+
this._lastTouchY = y;
115+
this.term.scrollLines(-Math.round(deltaY/10));
116+
}
117+
});
118+
parent.addEventListener("touchend", e => {
119+
this._lastTouch = null;
120+
});
121+
parent.addEventListener("touchcancel", e => {
122+
this._lastTouch = null;
123+
});
124+
102125
this.fit = () => {
103126
this.term.fit();
104127
setTimeout(() => {

0 commit comments

Comments
 (0)