fix(Terminal): Accept input from Chrome on Android

Xterm.js produces two kinds of events: onKey and onData. On a desktop,
these are effectively the same, but on mobile, IME inputs produce data
but not key presses. By listening to onData instead of onKey, we get
that input.

With some experimentation, I also found that we don't need the code to
handle enter, home, end, or Ctrl-Shift-V. All of these function as
expected without that code, so we can remove it and simplify this
further. :^)
This commit is contained in:
Sam Atkins 2024-05-14 16:00:59 +01:00
parent 2656b47640
commit 4ef3e53de3

View File

@ -28,9 +28,7 @@ class XTermIO {
}
bind () {
this.term.onKey(this.handleKey.bind(this));
this.term.attachCustomKeyEventHandler(this.handleKeyBeforeProcess.bind(this));
this.term.onData(this.handleData.bind(this));
(async () => {
for ( ;; ) {
@ -40,41 +38,8 @@ class XTermIO {
})();
}
async handleKeyBeforeProcess (evt) {
if ( evt.key === 'V' && evt.ctrlKey && evt.shiftKey && evt.type === 'keydown' ) {
const clipboard = navigator.clipboard;
const text = await clipboard.readText();
this.pty.out.write(text);
}
}
handleKey ({ key, domEvent }) {
const pty = this.pty;
const handlers = {
Enter: () => {
pty.out.write('\n');
},
// Backspace: () => {
// pty.out.write('\x08');
// },
// Delete: () => {
// pty.out.write('\x1B[3~');
// },
Home: () => {
pty.out.write('\x1B[H');
},
End: () => {
pty.out.write('\x1B[F');
}
}
if ( handlers.hasOwnProperty(domEvent.key) ) {
const writeKey = handlers[domEvent.key]();
if ( ! writeKey ) return;
}
pty.out.write(key);
handleData ( data ) {
this.pty.out.write(data);
}
}