Cannot insert right curly brace "}" (Modeswitch+L)


#1

Like the title says.

a) If I enable Key Binding Resolver (with ctrl+.), it states: “Key Binding Resolver: }” as if it matched. It does not show it being mapped to anything else. It’s as if I simply typed “a”. Yet “}” is never inserted. I cannot even enter “}” in the developer tools console of Atom.

b.1) The (custom) XKB keymap I use employs AltGr (RALT) as modeswitch which switches the keys “asdfghjkl” (home row qwerty) to be “@{[(<>)]}”. All these other keys work, I can type “@{[(<>)]” in Atom just fine, but specifically not “}” (AltGr+L). “=?!$+∈×^∧⋅~_” et cetera also work fine, and they all use AltGr+.

b.2) No other applications (including Chrome) has any problems with “}” or any other keys I have mapped to the modeswitched group.

c) Exchanging “}” and “]” in my XKB layout file confirms that it is AltGr+L that is not working. Whatever I map to the second group of the L key does not get inserted as text in Atom, even though it obviously detects it.

d) Problem persists with --safe parameter. My init script is empty. Doesn’t work in a clean install either.

e) Linux x64; tested both Atom 1.19.7 and 1.21.0-beta0.

I would like to know what kind of code I could put in my init.coffee or enter in the console to sort of investigate what actually happens in the key event handler when it receives “}” (or whatever I have mapped to AltGr+L) – like why does it fail to activate the default action of inserting it into the text?

Is there a sort of “hack” I can use to forcefully bind “}” to the “default action”? It seems Atom does actually receive “}” but it refuses to take action because this happens to be AltGr+L…?


#2

Hey,

What keyboard layout are you using?
Also what distro/VM of Linux?


#3

Lubuntu 17.07. Not using any desktop environment though, just XMonad window manager.

The keyboard layout is custom, based on Norwegian + Colemak. If you actually want to see it:

partial default alphanumeric_keys
xkb_symbols “basic” {
include “no(basic)” // Based on Norwegian layout.
include “capslock(backspace)” // Make Caps Lock act as Backspace.

name[Group1] = “FSH Colemak (Norwegian)”;

// Use RWIN for XMonad.
key <LWIN> { type=“ONE_LEVEL”, [Super_L] };

// Make AltGr select group +1 and RWIN select group +2.
replace key <RALT> { type=“ONE_LEVEL”, [ Mode_switch, Mode_switch ] };
replace key <RWIN> {
type=“ONE_LEVEL”,
symbols[Group1] = [NoSymbol],
symbols[Group2] = [NoSymbol],
symbols[Group3] = [NoSymbol],
symbols[Group4] = [NoSymbol],
actions[Group1] = [ SetGroup(group=3), SetGroup(group=3) ],
actions[Group2] = [ SetGroup(group=4), SetGroup(group=4) ]
};

key <TLDE> { [ U2018, U2019 ] // LEFT SINGLE QUOTATION MARK, RIGHT SINGLE QUOTATION MARK
, [ U201C, U201D ] // LEFT DOUBLE QUOTATION MARK, RIGHT DOUBLE QUOTATION MARK
, [ U00B1, U00F7 ] // PLUS-MINUS SIGN, DIVISION SIGN
};

[…]

key <AC08> { [ U0065, U0045 ] // LATIN SMALL LETTER E, LATIN CAPITAL LETTER E
, [ U005D, NoSymbol ] // RIGHT SQUARE BRACKET, —
, [ U2203, U2204 ] // THERE EXISTS, THERE DOES NOT EXIST
, [ U03B5, NoSymbol ] // GREEK SMALL LETTER EPSILON, —
};
key <AC09> { [ U0069, U0049 ] // LATIN SMALL LETTER I, LATIN CAPITAL LETTER I
, [ U007D, NoSymbol ] // RIGHT CURLY BRACKET, —
, [ Left, NoSymbol ] // Left, —
};
key <AC10> { [ U006F, U004F ] // LATIN SMALL LETTER O, LATIN CAPITAL LETTER O
, [ U007E, U0303 ] // TILDE, COMBINING TILDE
, [ Down, NoSymbol ] // Down, —
};

The offending key is AC09 (L). Second group, U007D is “}”.


#4

Trying to hook into atom.keymaps.onDidFailToMatchBinding() (I just put in console.log("onDidFailMatchBinding:", e.eventType, e.keystrokes, e.keyboardEventTarget);):

onDidFailMatchBinding: keydown modechange <input class=​"hidden-input" …
onDidFailMatchBinding: keydown { <input class=​"hidden-input" …
onDidFailMatchBinding: keyup ^{ <input class=​"hidden-input" …
onDidFailMatchBinding: keyup ^modechange <input class=​"hidden-input" …

The above is when I typed AltGr+S and it inserts “{”.

onDidFailMatchBinding: keydown modechange <input class=​"hidden-input" …
onDidFailMatchBinding: keydown } <input class=​"hidden-input" …
onDidFailMatchBinding: keyup ^} <input class=​"hidden-input" …
onDidFailMatchBinding: keyup ^modechange <input class=​"hidden-input" …

This is from typing AltGr+L: it looks identical to me, but it does not insert “}” in the buffer/window/whatever has focus!!

How can I check what the difference is / why it doesn’t react to it?


#5

After doing some more digging, I still have no idea why AltGr+L fails to insert its event.key (which is “}”). I went to /usr/share/atom/resources/app/node_modules/atom-keymap/ and figured as follows:

on keydown event for AltGr+X (where X is any key other than L) the event goes through, fails to match any key-binding, but the character is inserted “naturally” by default event handling (preventDefault is false). There seems to me no difference about the events given by AltGr+L but for whatever reason its event.key is not inserted.

As a HACK I simply modified keymap-manager.js in atom-keymap with

if ((event.defaultPrevented || event.key == "}") && event.type === 'keydown') {
   this.simulateTextInput(event);
}

and running atom -d it “works.” But of course this is not a real solution, I just got sick of trying to make it work properly (and have no idea where the code for the actual default event key handling is), when all I want to do right now is write some LaTeX.


#6

Update: having some more time, I dug around further and modified my keymap. Apparently the fact that the key is “L” has nothing to do with it. The problem is that the next XKB group on the L-key has “Left” in it. That is: the fact that RWIN+L on my keyboard is Left (like the cursor key), prevents it from default-actioning on AltGr+L even if I DO NOT actually press RWIN. Why would this be so? I have no idea, it’s weird as hell.

No other application has had this problem that I’ve seen.

If I remove the binding of RWIN+L or change it to something else (like a non-cursor key), then it works. Likewise if I move my cursor keys from the LP;’-keys (LPØÆ on Norwegian QWERTY) to somewhere else, then those keys will stop working with AltGr/Modeswitch.

Basically the frame (Chromium or Electron?) or whatever that Atom is built on (at this point I assume it’s their problem, not Atom), is doing something it shouldn’t do when resolving keys to symbols? It seems to be letting the fact that I have other functions bound to those keys (w/ certain modifier keys) in my XKB table influence its behavior even when I do not use those modifiers.

I’ll just work around this with my hack for now, I don’t have time to actually dig into Chromium/Electron code… :frowning:


#7

Can you reproduce this issue in Chromium? If so then you can report an issue to them.

Our current version of Electron is using chromium 56 I believe. If you want to try the same version in the case the latest stable version of chromium works.


#8

Yeah I was able to reproduce it in Chromium, though I didn’t file a bug report because the reporting process seems rather complicated & unsure where it should go. Plus my problem is rather esoteric so it’s hard to explain what is actually wrong.

However, for future readers of this thread, I was able to work around the problem by modifying my XKB in the following way:

  key <AC09> { symbols[Group1] = [ U0069, U0049 ] // LATIN SMALL LETTER I, LATIN CAPITAL LETTER I
             , symbols[Group2] = [ U007D, NoSymbol ] // RIGHT CURLY BRACKET, ---
             , symbols[Group3] = [ NoSymbol, NoSymbol ] // don't output anything, we'll redirect it instead
             , symbols[Group4] = [ U2190, NoSymbol ] // LEFTWARDS ARROW, ---
             , actions[Group3] = [ RedirectKey(key=<LEFT>) ] // redirect RWIN+L --> Left key
  };

It seems Chromium has some special handling of keys that (with some combination of mods) will output Left/Right/Up/Down/etc. so the idea was to make my RWIN+L (etc.) redirect its keycode to the actual cursor-key instead of producing the keysym for Left/etc. This stops Chromium et al from trying to treat the keys as special and suppress or override the other combinations you might do with it (like accessing group 2 or 4).