Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

hotkeys: Show Level 2 Shift key symbol for Shift key in popovers.

Sayam Samalf5bedd9501ea
diff --git a/web/src/common.ts b/web/src/common.ts
index ebb6f18e9c2..6f6f3f808cd 100644
--- a/web/src/common.ts
+++ b/web/src/common.ts
@@ -113,6 +113,19 @@ export function adjust_mac_hotkey_hints(hotkeys: string[]): void {
}
}
+// We convert the Shift key with ⇧ (Level 2 Select Symbol) in the
+// popover menu hotkey hints. This helps us reduce the width of
+// the popover menus.
+export function adjust_shift_hotkey(hotkeys: string[]): boolean {
+ for (const [index, hotkey] of hotkeys.entries()) {
+ if (hotkey === "Shift") {
+ hotkeys[index] = "⇧";
+ return true;
+ }
+ }
+ return false;
+}
+
// See https://zulip.readthedocs.io/en/latest/development/authentication.html#password-form-implementation
// for design details on this feature.
function set_password_toggle_label(
diff --git a/web/src/templates.js b/web/src/templates.js
index b78563943ee..b672ab7bb15 100644
--- a/web/src/templates.js
+++ b/web/src/templates.js
@@ -132,9 +132,16 @@ Handlebars.registerHelper("popover_hotkey_hints", (...hotkeys) => {
hotkeys.pop(); // Handlebars options
let hotkey_hints = "";
common.adjust_mac_hotkey_hints(hotkeys);
+ const shift_hotkey_exists = common.adjust_shift_hotkey(hotkeys);
for (const hotkey of hotkeys) {
hotkey_hints += `<span class="popover-menu-hotkey-hint">${hotkey}</span>`;
}
- const result = `<span class="popover-menu-hotkey-hints">${hotkey_hints}</span>`;
- return new Handlebars.SafeString(result);
+ if (shift_hotkey_exists) {
+ return new Handlebars.SafeString(
+ `<span class="popover-menu-hotkey-hints popover-contains-shift-hotkey" data-hotkey-hints="${hotkeys}">${hotkey_hints}</span>`,
+ );
+ }
+ return new Handlebars.SafeString(
+ `<span class="popover-menu-hotkey-hints">${hotkey_hints}</span>`,
+ );
});
diff --git a/web/src/tippyjs.ts b/web/src/tippyjs.ts
index 9b244f4516e..e6f76ff9598 100644
--- a/web/src/tippyjs.ts
+++ b/web/src/tippyjs.ts
@@ -621,4 +621,19 @@ export function initialize(): void {
instance.destroy();
},
});
+
+ delegate("body", {
+ target: ".popover-contains-shift-hotkey",
+ trigger: "mouseenter",
+ placement: "top",
+ appendTo: () => document.body,
+ onShow(instance) {
+ const hotkey_hints = $(instance.reference).attr("data-hotkey-hints");
+ if (hotkey_hints) {
+ instance.setContent(hotkey_hints.replace("⇧", "Shift").replaceAll(",", " + "));
+ return undefined;
+ }
+ return false;
+ },
+ });
}
diff --git a/web/tests/templates.test.js b/web/tests/templates.test.js
index 6cd87a31a6b..36ee1c7c79c 100644
--- a/web/tests/templates.test.js
+++ b/web/tests/templates.test.js
@@ -55,12 +55,24 @@ run_test("tooltip_hotkey_hints", () => {
});
run_test("popover_hotkey_hints", () => {
+ const args = {
+ hotkey_one: "Ctrl",
+ hotkey_two: "[",
+ };
+
+ const html = require("./templates/popover_hotkey_hints.hbs")(args);
+ const expected_html = `<span class="popover-menu-hotkey-hints"><span class="popover-menu-hotkey-hint">${args.hotkey_one}</span><span class="popover-menu-hotkey-hint">${args.hotkey_two}</span></span>\n`;
+ assert.equal(html, expected_html);
+});
+
+run_test("popover_hotkey_hints_shift_hotkey", () => {
const args = {
hotkey_one: "Shift",
hotkey_two: "V",
};
const html = require("./templates/popover_hotkey_hints.hbs")(args);
- const expected_html = `<span class="popover-menu-hotkey-hints"><span class="popover-menu-hotkey-hint">${args.hotkey_one}</span><span class="popover-menu-hotkey-hint">${args.hotkey_two}</span></span>\n`;
+ args.hotkey_one = "⇧"; // adjust_shift_hotkey
+ const expected_html = `<span class="popover-menu-hotkey-hints popover-contains-shift-hotkey" data-hotkey-hints="${args.hotkey_one},${args.hotkey_two}"><span class="popover-menu-hotkey-hint">${args.hotkey_one}</span><span class="popover-menu-hotkey-hint">${args.hotkey_two}</span></span>\n`;
assert.equal(html, expected_html);
});