]> git.proxmox.com Git - mirror_xterm.js.git/blobdiff - src/xterm.js
Merge remote-tracking branch 'upstream/master' into 118_support_custom_keydown_handler
[mirror_xterm.js.git] / src / xterm.js
index 39b4eb16316f83605c26fe1a6b5efa9699e2a99b..9afc08fd613895540246105769b00dc7af39615e 100644 (file)
       this.queue = '';
       this.scrollTop = 0;
       this.scrollBottom = this.rows - 1;
+      this.customKeydownHandler = null;
 
       // modes
       this.applicationKeypad = false;
       this.write(data + '\r\n');
     };
 
+    /**
+     * Attaches a custom keydown handler which is run before keys are processed, giving consumers of
+     * xterm.js ultimate control as to what keys should be processed by the terminal and what keys
+     * should not.
+     * @param {function} customKeydownHandler The custom KeyboardEvent handler to attach. This is a
+     *   function that takes a KeyboardEvent, allowing consumers to stop propogation and/or prevent
+     *   the default action. The function returns whether the event should be processed by xterm.js.
+     */
+    Terminal.prototype.attachCustomKeydownHandler = function(customKeydownHandler) {
+      this.customKeydownHandler = customKeydownHandler;
+    }
+
     /**
      * Handle a keydown event
      * Key Resources:
      * @param {KeyboardEvent} ev The keydown event to be handled.
      */
     Terminal.prototype.keyDown = function(ev) {
+      if (this.customKeydownHandler && this.customKeydownHandler(ev) === false) {
+        return false;
+      }
+
       if (!this.compositionHelper.keydown.bind(this.compositionHelper)(ev)) {
         return false;
       }