5digits / dactyl

Pentadactyl and other related Gecko extensions
Other
469 stars 98 forks source link

<C-[> no longer works in textareas #175

Open arxanas opened 8 years ago

arxanas commented 8 years ago

I principally use <C-[> to exit from insert mode because <ESC> is not very ergonomic. (I believe this keybinding was carried over from Vim.) As of https://github.com/5digits/dactyl/issues/168, typing <C-[> no longer works. Adding this entry does not work either, whether in my .pentadactylrc or when adding the mapping directly in the browser:

imap <C-[> <ESC>

<ESC> still works, but I don't like <ESC>.

Expected behavior: typing <C-[> while typing in a text field will remove the focus from that text field, and go back to normal mode.

Actual behavior: <C-[> has no effect in a text field.

betaveros commented 8 years ago

I also recently found <C-[> no longer doing anything in pass-through mode and I also somewhat need it (reveal.js gobbles up Escape...)

I'm on OS X 10.10.5, and digging into it in Firefox Developer Edition, it appears that the <C-[> event's charCode now 0 and so this condition is no longer triggered: https://github.com/5digits/dactyl/blob/c1f353789886cc3ad711269fd62face65b2f79c1/common/modules/dom.jsm#L1381

I don't know the right fix or how the KeyboardEvent's API is changing, but the event looks like it has code: "BracketLeft" and key: "[" attributes that one might test against.

betaveros commented 8 years ago

A questionable patch that seems to work:

diff --git a/common/modules/dom.jsm b/common/modules/dom.jsm
index efcc56b..45f1984 100644
--- a/common/modules/dom.jsm
+++ b/common/modules/dom.jsm
@@ -1341,7 +1341,16 @@ var DOM = Class("DOM", {
                 modifier += "M-";

             if (/^key/.test(event.type)) {
-                let charCode = event.type == "keyup" ? 0 : event.charCode; // Why? --Kris
+                let charCode = event.charCode;
+                if (event.key && "[\\]^_".indexOf(event.key) >= 0) {
+                    // The [Ctrl-Bug] documented below stopped working recently
+                    // (2016) and charCode is just 0 for those ctrl-keys for
+                    // some reason. Restore a good charCode to fall-through to
+                    // the third case.
+                    charCode = event.key.charCodeAt(0);
+                }
                 if (charCode == 0) {
                     if (event.keyCode in this.code_key) {
                         key = this.code_key[event.keyCode];

The conditional let charCode = event.type == "keyup" ? 0 : event.charCode; was introduced in the commit https://github.com/5digits/dactyl/commit/a1dbd3fa7affa951dec341f6b4056626b6effff2 ; I couldn't tell if it was still relevant so I just deleted it...

ernestorocha commented 8 years ago

It would be awesome to have this again! Anyone tried that solution ?