I am currently fairly sad because I have hit a wall with the ActionText/Trix editor that seems to be unfixable from my end. I was trying to wire up keyboard shortcuts for all of the Trix editor actions, and I wanted to make ctrl + [ the shortcut for "increase indent level" and ctrl + ] for "decrease indent level". I added data-trix-key="[" to the button, reloaded, and used the keyboard shortcut ... and nothing happened. After digging into the problem and the Trix source, I found this:
if character = String.fromCharCode(event.keyCode).toLowerCase()
In order to determine if a data-trix-key keyboard shortcut has been activated, you take the event.keyCode and use String.fromCharCode to get the corresponding string representation of the key pressed. For reasons that I do not understand, my keyboard (on an US Macbook with a US layout both physically and in software) seems to send different signals than they are expecting. I tested this by adding a simple event listener to log out some data:
So, when I press ctrl + [, the Trix code believes I have just pressed crtl + û and therefore doesn't believe I have triggered the keyboard shortcut. I have two questions, [1] is there a way I can resolve this on my end and/or [2] is there is strong reason to use String.fromCharCode(event.keyCode).toLowerCase() instead of event.key (https://caniuse.com/keyboardevent-key)?
I am currently fairly sad because I have hit a wall with the ActionText/Trix editor that seems to be unfixable from my end. I was trying to wire up keyboard shortcuts for all of the Trix editor actions, and I wanted to make
ctrl + [
the shortcut for "increase indent level" andctrl + ]
for "decrease indent level". I addeddata-trix-key="["
to the button, reloaded, and used the keyboard shortcut ... and nothing happened. After digging into the problem and the Trix source, I found this:(https://github.com/basecamp/trix/blob/520cc50afff2b90120f49038945eb0cb73d82535/src/trix/controllers/level_0_input_controller.coffee#L100).
In order to determine if a
data-trix-key
keyboard shortcut has been activated, you take theevent.keyCode
and useString.fromCharCode
to get the corresponding string representation of the key pressed. For reasons that I do not understand, my keyboard (on an US Macbook with a US layout both physically and in software) seems to send different signals than they are expecting. I tested this by adding a simple event listener to log out some data:And sure enough, these are my logs:
So, when I press
ctrl + [
, the Trix code believes I have just pressedcrtl + û
and therefore doesn't believe I have triggered the keyboard shortcut. I have two questions, [1] is there a way I can resolve this on my end and/or [2] is there is strong reason to useString.fromCharCode(event.keyCode).toLowerCase()
instead ofevent.key
(https://caniuse.com/keyboardevent-key)?