compose: Use event.key instead of deprecated event.keyCode.

There is no functionality change caused by this change. We turn the
event key to lowercase so hotkeys work even when Caps Lock is on as
it did before.

Tested by using the keybinds with and without Caps Lock in compose
box:
 - "Ctrl + B" and "Ctrl + Shift + B",
 - "Ctrl + I", and
 - "Ctrl + Shift + L".

(Also tested that "Ctrl + Shift + I" and "Ctrl + L" do not work.)
This commit is contained in:
Priyank Patel
2021-05-28 17:59:20 +00:00
committed by Tim Abbott
parent e5005cf4cc
commit 37f96e85ff
2 changed files with 18 additions and 15 deletions

View File

@@ -821,10 +821,14 @@ export function validate() {
}
export function handle_keydown(event, textarea) {
const code = event.keyCode || event.which;
const isBold = code === 66;
const isItalic = code === 73 && !event.shiftKey;
const isLink = code === 76 && event.shiftKey;
// The event.key property will have uppercase letter if
// the "Shift + <key>" combo was used or the Caps Lock
// key was on. We turn to key to lowercase so the keybindings
// work regardless of whether Caps Lock was on or not.
const key = event.key.toLowerCase();
const isBold = key === "b";
const isItalic = key === "i" && !event.shiftKey;
const isLink = key === "l" && event.shiftKey;
// detect Cmd and Ctrl key
const isCmdOrCtrl = common.has_mac_keyboard() ? event.metaKey : event.ctrlKey;