A platform for community discussion. Free, open, simple.
UX: Shortcuts for editor heading toolbar (#33578)
Martin Brennancbf88d617ed3
diff --git a/app/assets/javascripts/discourse/app/components/d-editor.gjs b/app/assets/javascripts/discourse/app/components/d-editor.gjsindex 45a7753f886..5df7b10abcf 100644--- a/app/assets/javascripts/discourse/app/components/d-editor.gjs+++ b/app/assets/javascripts/discourse/app/components/d-editor.gjs@@ -143,6 +143,10 @@ export default class DEditor extends Component {// These are defined in lib/composer/toolbar.js via addButton.// It includes shortcuts for top level toolbar buttons, as well// as the toolbar popup menu option shortcuts.++ // TODO (martin) Might be nice to automatically add these shortcuts+ // to keyboard-shortcuts-help.gjs at some point (the modal launched with+ // ?)const shortcuts = this.get("toolbar.shortcuts");Object.keys(shortcuts).forEach((sc) => {const button = shortcuts[sc];diff --git a/app/assets/javascripts/discourse/app/components/modal/keyboard-shortcuts-help.gjs b/app/assets/javascripts/discourse/app/components/modal/keyboard-shortcuts-help.gjsindex 741217fa764..731345ca294 100644--- a/app/assets/javascripts/discourse/app/components/modal/keyboard-shortcuts-help.gjs+++ b/app/assets/javascripts/discourse/app/components/modal/keyboard-shortcuts-help.gjs@@ -222,6 +222,58 @@ export default class KeyboardShortcutsHelp extends Component {keys1: [META, SHIFT, "."],keysDelimiter: PLUS,}),+ bold: buildShortcut("composing.bold", {+ keys1: [META, "b"],+ keysDelimiter: PLUS,+ }),+ italic: buildShortcut("composing.italic", {+ keys1: [META, "i"],+ keysDelimiter: PLUS,+ }),+ link: buildShortcut("composing.link", {+ keys1: [META, "k"],+ keysDelimiter: PLUS,+ }),+ preformatted: buildShortcut("composing.preformatted", {+ keys1: [META, "e"],+ keysDelimiter: PLUS,+ }),+ paragraph: buildShortcut("composing.paragraph", {+ keys1: [META, ALT, "0"],+ keysDelimiter: PLUS,+ }),+ heading1: buildShortcut("composing.heading_1", {+ keys1: [META, ALT, "1"],+ keysDelimiter: PLUS,+ }),+ heading2: buildShortcut("composing.heading_2", {+ keys1: [META, ALT, "2"],+ keysDelimiter: PLUS,+ }),+ heading3: buildShortcut("composing.heading_3", {+ keys1: [META, ALT, "3"],+ keysDelimiter: PLUS,+ }),+ heading4: buildShortcut("composing.heading_4", {+ keys1: [META, ALT, "4"],+ keysDelimiter: PLUS,+ }),+ toggleDirection: buildShortcut("composing.toggle_direction", {+ keys1: [META, SHIFT, "6"],+ keysDelimiter: PLUS,+ }),+ orderedList: buildShortcut("composing.ordered_list", {+ keys1: [META, SHIFT, "7"],+ keysDelimiter: PLUS,+ }),+ unorderedList: buildShortcut("composing.unordered_list", {+ keys1: [META, SHIFT, "8"],+ keysDelimiter: PLUS,+ }),+ blockquote: buildShortcut("composing.blockquote", {+ keys1: [META, SHIFT, "9"],+ keysDelimiter: PLUS,+ }),},},bookmarks: {diff --git a/app/assets/javascripts/discourse/app/lib/composer/toolbar.js b/app/assets/javascripts/discourse/app/lib/composer/toolbar.jsindex 0b95d68e72c..61624001b26 100644--- a/app/assets/javascripts/discourse/app/lib/composer/toolbar.js+++ b/app/assets/javascripts/discourse/app/lib/composer/toolbar.js@@ -234,6 +234,7 @@ export default class Toolbar extends ToolbarBase {translatedTitle: i18n("composer.heading_level_n_title", {levelNumber: headingLevel,}),+ shortcut: "Alt+" + headingLevel,condition: true,showActiveIcon: true,active: ({ state }) => {@@ -257,6 +258,7 @@ export default class Toolbar extends ToolbarBase {title: "composer.heading_level_paragraph_title",condition: true,showActiveIcon: true,+ shortcut: "Alt+0",active: ({ state }) => state?.inParagraph,action: this.onHeadingMenuAction.bind(this),});diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex e451ec7b3dd..42a826f9476 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -4776,6 +4776,19 @@ en:return: "%{shortcut} Return to composer"fullscreen: "%{shortcut} Fullscreen composer"insert_current_time: "%{shortcut} Insert current time"+ bold: "%{shortcut} Bold"+ italic: "%{shortcut} Italic"+ link: "%{shortcut} Insert link"+ preformatted: "%{shortcut} Preformatted text"+ paragraph: "%{shortcut} Paragraph"+ heading_1: "%{shortcut} Heading 1"+ heading_2: "%{shortcut} Heading 2"+ heading_3: "%{shortcut} Heading 3"+ heading_4: "%{shortcut} Heading 4"+ toggle_direction: "%{shortcut} Toggle text direction"+ ordered_list: "%{shortcut} Ordered list"+ unordered_list: "%{shortcut} Unordered list"+ blockquote: "%{shortcut} Blockquote"bookmarks:title: "Bookmarking"enter: "%{shortcut} Save and close"diff --git a/spec/system/composer/prosemirror_editor_spec.rb b/spec/system/composer/prosemirror_editor_spec.rbindex a05f9d4b64c..55a699f3634 100644--- a/spec/system/composer/prosemirror_editor_spec.rb+++ b/spec/system/composer/prosemirror_editor_spec.rb@@ -443,17 +443,16 @@ describe "Composer - ProseMirror editor", type: :system doexpect(rich).to have_css("blockquote", text: "This is a blockquote")end- # TODO (martin) Bring this back once we decide what to do for cross-platform shortcuts- xit "supports Ctrl + Shift + 1-4 for headings, 0 for reset" do+ it "supports Ctrl + Shift + 1-4 for headings, 0 for reset" doopen_composer_and_toggle_rich_editor(1..4).each do |i|composer.type_content("\nHeading #{i}")- composer.send_keys([PLATFORM_KEY_MODIFIER, :shift, i.to_s])+ composer.send_keys([PLATFORM_KEY_MODIFIER, :alt, i.to_s])expect(rich).to have_css("h#{i}", text: "Heading #{i}")end- composer.send_keys([PLATFORM_KEY_MODIFIER, :shift, "0"])+ composer.send_keys([PLATFORM_KEY_MODIFIER, :alt, "0"])expect(rich).not_to have_css("h4")end