Created
April 4, 2017 20:09
-
-
Save litera/8683f5ce3d6d50267749b13c9d4ce899 to your computer and use it in GitHub Desktop.
Slack common keyboard shortcuts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
alert("Initializing additional Slack keyboard shortcuts.\n\nCTRL+B = bold\nCTRL+I = italic\nCTRL+S = strike through\nCTRL+P = preformatted\nCTRL+< = code"); | |
var keys = { | |
b: "*", | |
i: "_", | |
"<": "`", | |
p: "\n```\n", | |
s : "~" | |
}; | |
$("#msg_input") | |
.off(".slack") | |
.on("keyup.slack", function(evt) { | |
if (!keys[evt.key]) return; | |
if (!evt.ctrlKey) return; | |
evt.preventDefault(); | |
var head = this.selectionStart; | |
var tail = this.selectionEnd; | |
var left = this.value.substr(0, this.selectionStart); | |
var mid = this.value.substring(this.selectionStart, this.selectionEnd); | |
var right = this.value.substr(this.selectionEnd); | |
this.value = left + keys[evt.key] + mid + keys[evt.key] + right; | |
var shift = keys[evt.key].length; | |
this.selectionEnd = tail + shift; | |
this.selectionStart = head + shift; | |
$(this).trigger("input"); | |
}) | |
.on("keydown.slack", function(evt){ | |
if (evt.ctrlKey && (evt.key === "s" || evt.key === "p")) { | |
evt.preventDefault(); | |
evt.stopPropagation(); | |
} | |
if (evt.shiftKey && evt.ctrlKey && evt.key === "?") { | |
evt.preventDefault(); | |
evt.stopPropagation(); | |
alert("Additional Slack keyboard shortcuts are enabled.\n\nCTRL+B = bold\nCTRL+I = italic\nCTRL+S = strike through\nCTRL+P = preformatted\nCTRL+< = code"); | |
} | |
}); | |
}); | |
void(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment