Pārlūkot izejas kodu

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. :^)
Sam Atkins 1 gadu atpakaļ
vecāks
revīzija
4ef3e53de3
1 mainītis faili ar 3 papildinājumiem un 38 dzēšanām
  1. 3 38
      packages/terminal/src/main.js

+ 3 - 38
packages/terminal/src/main.js

@@ -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);
     }
 }