Skip to content

Commit

Permalink
markdown shortcuts: Replace Ctrl+L with Ctrl+L+Shift for link insertion.
Browse files Browse the repository at this point in the history
As Ctrl-L was interfering with browsers's Ctrl-L, the shortcut key
for link insertion is changed to Ctrl+L+Shift.
  • Loading branch information
YJDave authored and timabbott committed Feb 2, 2018
1 parent ef42bb2 commit b519f1c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions frontend_tests/node_tests/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ people.add(bob);
event.keyCode = 76;
event.which = undefined;
event.ctrlKey = true;
event.shiftKey = true;
compose.handle_keydown(event);
assert.equal("Any [link](url).", $('#compose-textarea').val());
// Test if exec command is not enabled in browser.
Expand Down
14 changes: 7 additions & 7 deletions static/js/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,11 +675,11 @@ exports.handle_keydown = function (event) {
var code = event.keyCode || event.which;
var textarea = $("#compose-textarea");
var range = textarea.range();
var bKey = 66;
var iKey = 73;
var lKey = 76;
var isBold = code === 66;
var isItalic = code === 73;
var isLink = code === 76 && event.shiftKey;

if ((code === bKey || code === iKey || code === lKey) && (event.ctrlKey || event.metaKey)) {
if (isBold || isItalic || isLink && (event.ctrlKey || event.metaKey)) {
function add_markdown(markdown) {
var textarea = $("#compose-textarea");
var range = textarea.range();
Expand All @@ -689,21 +689,21 @@ exports.handle_keydown = function (event) {
event.preventDefault();
}

if (code === bKey) {
if (isBold) {
// ctrl + b: Convert selected text to bold text
add_markdown("**" + range.text + "**");
if (!range.length) {
textarea.caret(textarea.caret() - 2);
}
}
if (code === iKey) {
if (isItalic) {
// ctrl + i: Convert selected text to italic text
add_markdown("*" + range.text + "*");
if (!range.length) {
textarea.caret(textarea.caret() - 1);
}
}
if (code === lKey) {
if (isLink) {
// ctrl + l: Insert a link to selected text
add_markdown("[" + range.text + "](url)");
var position = textarea.caret();
Expand Down

0 comments on commit b519f1c

Please sign in to comment.