Skip to content

Commit

Permalink
Merge pull request pandao#233 from mrjlynch/master
Browse files Browse the repository at this point in the history
Added support for Mac keyboard shortcuts
  • Loading branch information
pandao committed May 15, 2016
2 parents edc2169 + a8b8ae2 commit dc80a77
Showing 1 changed file with 40 additions and 37 deletions.
77 changes: 40 additions & 37 deletions src/editormd.js
Original file line number Diff line number Diff line change
Expand Up @@ -3170,17 +3170,20 @@
}
};

var isMac = navigator.platform.toUpperCase().indexOf('MAC')>=0;
var key = isMac ? "Cmd" : "Ctrl";

editormd.keyMaps = {
"Ctrl-1" : "h1",
"Ctrl-2" : "h2",
"Ctrl-3" : "h3",
"Ctrl-4" : "h4",
"Ctrl-5" : "h5",
"Ctrl-6" : "h6",
"Ctrl-B" : "bold", // if this is string == editormd.toolbarHandlers.xxxx
"Ctrl-D" : "datetime",

"Ctrl-E" : function() { // emoji
[key + "-1"] : "h1",
[key + "-2"] : "h2",
[key + "-3"] : "h3",
[key + "-4"] : "h4",
[key + "-5"] : "h5",
[key + "-6"] : "h6",
[key + "-B"] : "bold", // if this is string == editormd.toolbarHandlers.xxxx
[key + "-D"] : "datetime",

[key + "Ctrl-E"] : function() { // emoji
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
Expand All @@ -3197,10 +3200,10 @@
cm.setCursor(cursor.line, cursor.ch + 1);
}
},
"Ctrl-Alt-G" : "goto-line",
"Ctrl-H" : "hr",
"Ctrl-I" : "italic",
"Ctrl-K" : "code",
[key + "-Alt-G"] : "goto-line",
[key + "-H"] : "hr",
[key + "-I"] : "italic",
[key + "-K"] : "code",

"Ctrl-L" : function() {
var cm = this.cm;
Expand All @@ -3215,7 +3218,7 @@
cm.setCursor(cursor.line, cursor.ch + 1);
}
},
"Ctrl-U" : "list-ul",
[key + "-U"] : "list-ul",

"Shift-Ctrl-A" : function() {
var cm = this.cm;
Expand All @@ -3235,10 +3238,10 @@
}
},

"Shift-Ctrl-C" : "code",
"Shift-Ctrl-Q" : "quote",
"Shift-Ctrl-S" : "del",
"Shift-Ctrl-K" : "tex", // KaTeX
["Shift" + key + "-C"] : "code",
["Shift" + key + "Q"] : "quote",
["Shift" + key + "S"] : "del",
["Shift" + key + "K"] : "tex", // KaTeX

"Shift-Alt-C" : function() {
var cm = this.cm;
Expand All @@ -3252,16 +3255,16 @@
}
},

"Shift-Ctrl-Alt-C" : "code-block",
"Shift-Ctrl-H" : "html-entities",
"Shift-Alt-H" : "help",
"Shift-Ctrl-E" : "emoji",
"Shift-Ctrl-U" : "uppercase",
"Shift-Alt-U" : "ucwords",
"Shift-Ctrl-Alt-U" : "ucfirst",
"Shift-Alt-L" : "lowercase",
["Shift-" + key + "-Alt-C"] : "code-block",
["Shift-" + key + "-H"] : "html-entities",
"Shift-Alt-H" : "help",
["Shift-" + key + "-E"] : "emoji",
["Shift-" + key + "-U"] : "uppercase",
"Shift-Alt-U" : "ucwords",
["Shift-" + key + "-Alt-U"] : "ucfirst",
"Shift-Alt-L" : "lowercase",

"Shift-Ctrl-I" : function() {
["Shift-" + key + "-I"] : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
Expand All @@ -3275,15 +3278,15 @@
}
},

"Shift-Ctrl-Alt-I" : "image",
"Shift-Ctrl-L" : "link",
"Shift-Ctrl-O" : "list-ol",
"Shift-Ctrl-P" : "preformatted-text",
"Shift-Ctrl-T" : "table",
"Shift-Alt-P" : "pagebreak",
"F9" : "watch",
"F10" : "preview",
"F11" : "fullscreen",
["Shift-" + key + "-Alt-I"] : "image",
["Shift-" + key + "-L"] : "link",
["Shift-" + key + "-O"] : "list-ol",
["Shift-" + key + "-P"] : "preformatted-text",
["Shift-" + key + "-T"] : "table",
"Shift-Alt-P" : "pagebreak",
"F9" : "watch",
"F10" : "preview",
"F11" : "fullscreen",
};

/**
Expand Down

0 comments on commit dc80a77

Please sign in to comment.