compose_ui: Add shortcut for code spans.

This commit is contained in:
Aditya Bajaj 2024-04-06 22:05:18 +08:00
parent f4d109c289
commit 6c7b7665ea
3 changed files with 13 additions and 0 deletions

View File

@ -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```";

View File

@ -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: `\

View File

@ -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