From 6c7b7665ea8db7cc76fba058a90de2e7de89e563 Mon Sep 17 00:00:00 2001 From: Aditya Bajaj Date: Sat, 6 Apr 2024 22:05:18 +0800 Subject: [PATCH] compose_ui: Add shortcut for code spans. --- web/src/compose_ui.ts | 3 +++ web/src/info_overlay.ts | 1 + web/tests/compose_ui.test.js | 9 +++++++++ 3 files changed, 13 insertions(+) diff --git a/web/src/compose_ui.ts b/web/src/compose_ui.ts index ed8488c59a..3a8363dfe6 100644 --- a/web/src/compose_ui.ts +++ b/web/src/compose_ui.ts @@ -404,6 +404,8 @@ export function handle_keydown( type = "italic"; } else if (key === "l" && event.shiftKey) { type = "link"; + } else if (key === "c" && event.shiftKey) { + type = "code"; } // detect Cmd and Ctrl key @@ -1013,6 +1015,7 @@ export function format_text( break; } case "code": { + // Ctrl + Shift + C: Toggle code syntax on selection. const inline_code_syntax = "`"; let block_code_syntax_start = "```\n"; let block_code_syntax_end = "\n```"; diff --git a/web/src/info_overlay.ts b/web/src/info_overlay.ts index c88f437228..3b37c54ba8 100644 --- a/web/src/info_overlay.ts +++ b/web/src/info_overlay.ts @@ -129,6 +129,7 @@ This text won't be visible until the user clicks. def zulip(): print "Zulip" \`\`\``, + usage_html: format_usage_html("Ctrl", "Shift", "C"), }, { markdown: `\ diff --git a/web/tests/compose_ui.test.js b/web/tests/compose_ui.test.js index a9f20c9ddf..8a05f0e08e 100644 --- a/web/tests/compose_ui.test.js +++ b/web/tests/compose_ui.test.js @@ -1179,6 +1179,15 @@ run_test("markdown_shortcuts", ({override_rewire}) => { compose_ui.handle_keydown(event, $("textarea#compose-textarea")); assert.equal(format_text_type, "link"); format_text_type = undefined; + + // Test code block insertion: + // Mac = Cmd+Shift+C + // Windows/Linux = Ctrl+Shift+C + event.key = "c"; + event.shiftKey = true; + compose_ui.handle_keydown(event, $("textarea#compose-textarea")); + assert.equal(format_text_type, "code"); + format_text_type = undefined; } // This function cross tests the Cmd/Ctrl + Markdown shortcuts in