Skip to content

A platform for community discussion. Free, open, simple.

DEV: Add ability to hide shortcut in title (#32860)

Keegan George1a5377cf9341
diff --git a/app/assets/javascripts/discourse/app/lib/composer/toolbar.js b/app/assets/javascripts/discourse/app/lib/composer/toolbar.js
index 878aadb8a7c..034cf2aae09 100644
--- a/app/assets/javascripts/discourse/app/lib/composer/toolbar.js
+++ b/app/assets/javascripts/discourse/app/lib/composer/toolbar.js
@@ -148,6 +148,7 @@ export default class Toolbar {
preventFocus: buttonAttrs.preventFocus || false,
condition: buttonAttrs.condition || (() => true),
shortcutAction: buttonAttrs.shortcutAction, // (optional) custom shortcut action
+ hideShortcutInTitle: buttonAttrs.hideShortcutInTitle || false, // (optional) hide shortcut in title
};
if (buttonAttrs.sendAction) {
@@ -160,7 +161,12 @@ export default class Toolbar {
PLATFORM_KEY_MODIFIER + "+"
)}${translateModKey(buttonAttrs.shortcut)}`;
- createdButton.title = `${title} (${shortcutTitle})`;
+ if (buttonAttrs.hideShortcutInTitle) {
+ createdButton.title = title;
+ } else {
+ createdButton.title = `${title} (${shortcutTitle})`;
+ }
+
this.shortcuts[
`${PLATFORM_KEY_MODIFIER}+${buttonAttrs.shortcut}`.toLowerCase()
] = createdButton;
diff --git a/app/assets/javascripts/discourse/tests/acceptance/composer-test.js b/app/assets/javascripts/discourse/tests/acceptance/composer-test.js
index c036e67c974..f0c2553887e 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/composer-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/composer-test.js
@@ -1443,6 +1443,34 @@ import { i18n } from "discourse-i18n";
);
});
+ test("buttons with shortcuts can have their shortcut in title conditionally hidden", async function (assert) {
+ withPluginApi((api) => {
+ api.onToolbarCreate((toolbar) => {
+ toolbar.addButton({
+ id: "smile",
+ group: "extras",
+ name: "smile",
+ icon: "far-face-smile",
+ title: "cheese",
+ shortcut: "ALT+S",
+ hideShortcutInTitle: true,
+ });
+ });
+ });
+
+ await visit("/t/internationalization-localization/280");
+ await click(".post-controls button.reply");
+ await fillIn(".d-editor-input", "hello the world");
+
+ assert
+ .dom(".d-editor-button-bar .smile")
+ .hasAttribute(
+ "title",
+ i18n("cheese"),
+ "shows the title without the shortcut"
+ );
+ });
+
test("buttons can support a shortcut that triggers a custom action", async function (assert) {
withPluginApi("1.37.1", (api) => {
api.onToolbarCreate((toolbar) => {