keyboard-shortcuts: Add class to arrow keys for Mac shortcuts.

The <kbd> elements in `static.templates.keyboard_shortcuts.hbs`
that are arrow keys have a class of "arrow-key". This adds that
class to arrow keys that are updated via `adjust_mac_shortcuts`.

Follow-up task due to changes introduced in #22330.
This commit is contained in:
Lauryn Menard 2022-07-13 12:51:34 +02:00 committed by Tim Abbott
parent 7553c7ca4e
commit 35e9e4cd3b
2 changed files with 11 additions and 1 deletions

View File

@ -112,6 +112,8 @@ run_test("adjust_mac_shortcuts mac non-defaults", ({override}) => {
override(navigator, "platform", "MacIntel");
const kbd_element = false;
const test_items = [];
let key_no = 1;
@ -119,6 +121,7 @@ run_test("adjust_mac_shortcuts mac non-defaults", ({override}) => {
const test_item = {};
const $stub = $.create("hotkey_" + key_no);
$stub.text(old_key);
assert.equal($stub.hasClass("arrow-key"), false);
if (fn_shortcuts.has(old_key)) {
$stub.before = ($elem) => {
assert.equal($elem, inserted_fn_key);
@ -126,6 +129,7 @@ run_test("adjust_mac_shortcuts mac non-defaults", ({override}) => {
}
test_item.$stub = $stub;
test_item.mac_key = mac_key;
test_item.adds_arrow_key = fn_shortcuts.has(old_key) && kbd_element;
test_items.push(test_item);
key_no += 1;
}
@ -134,11 +138,11 @@ run_test("adjust_mac_shortcuts mac non-defaults", ({override}) => {
$.create(".markdown_content", {children});
const kbd_element = false;
common.adjust_mac_shortcuts(".markdown_content", kbd_element);
for (const test_item of test_items) {
assert.equal(test_item.$stub.text(), test_item.mac_key);
assert.equal(test_item.$stub.hasClass("arrow-key"), test_item.adds_arrow_key);
}
});
@ -162,6 +166,8 @@ run_test("adjust_mac_shortcuts mac defaults", ({override}) => {
override(navigator, "platform", "MacIntel");
const kbd_element = true;
const test_items = [];
let key_no = 1;
@ -169,6 +175,7 @@ run_test("adjust_mac_shortcuts mac defaults", ({override}) => {
const test_item = {};
const $stub = $.create("hotkey_" + key_no);
$stub.text(old_key);
assert.equal($stub.hasClass("arrow-key"), false);
if (fn_shortcuts.has(old_key)) {
$stub.before = ($elem) => {
assert.equal($elem, inserted_fn_key);
@ -176,6 +183,7 @@ run_test("adjust_mac_shortcuts mac defaults", ({override}) => {
}
test_item.$stub = $stub;
test_item.mac_key = mac_key;
test_item.adds_arrow_key = fn_shortcuts.has(old_key) && kbd_element;
test_items.push(test_item);
key_no += 1;
}
@ -188,6 +196,7 @@ run_test("adjust_mac_shortcuts mac defaults", ({override}) => {
for (const test_item of test_items) {
assert.equal(test_item.$stub.text(), test_item.mac_key);
assert.equal(test_item.$stub.hasClass("arrow-key"), test_item.adds_arrow_key);
}
});

View File

@ -80,6 +80,7 @@ export function adjust_mac_shortcuts(key_elem_class: string, kbd_elem = true): v
if (fn_shortcuts.has(key_text)) {
if (kbd_elem) {
$(this).before("<kbd>Fn</kbd> + ");
$(this).addClass("arrow-key");
} else {
$(this).before("<code>Fn</code> + ");
}