Merge pull request #810 from thelounge/xpaw/color-hotkeys

Implement color hotkeys
This commit is contained in:
Pavel Djundik 2017-03-31 19:17:16 +03:00 committed by GitHub
commit 212703d162
2 changed files with 187 additions and 39 deletions

View File

@ -390,6 +390,62 @@
</div> </div>
</div> </div>
<div class="help-item">
<div class="subject">
<kbd>Ctrl</kbd> + <kbd>K</kbd>
</div>
<div class="description">
<p>
Mark any text typed after this shortcut to be colored. After
hitting this shortcut, enter an integer in the
<code>0—15</code> range to select the desired color.
</p>
<p>
A color reference can be found
<a href="http://www.mirc.com/colors.html" target="_blank">here</a>.
</p>
</div>
</div>
<div class="help-item">
<div class="subject">
<kbd>Ctrl</kbd> + <kbd>B</kbd>
</div>
<div class="description">
<p>Mark all text typed after this shortcut as bold.</p>
</div>
</div>
<div class="help-item">
<div class="subject">
<kbd>Ctrl</kbd> + <kbd>U</kbd>
</div>
<div class="description">
<p>Mark all text typed after this shortcut as underlined.</p>
</div>
</div>
<div class="help-item">
<div class="subject">
<kbd>Ctrl</kbd> + <kbd>I</kbd>
</div>
<div class="description">
<p>Mark all text typed after this shortcut as italics.</p>
</div>
</div>
<div class="help-item">
<div class="subject">
<kbd>Ctrl</kbd> + <kbd>O</kbd>
</div>
<div class="description">
<p>
Mark all text typed after this shortcut to be reset to its
original formatting.
</p>
</div>
</div>
<h3>On macOS</h3> <h3>On macOS</h3>
<div class="help-item"> <div class="help-item">
@ -403,13 +459,69 @@
<div class="help-item"> <div class="help-item">
<div class="subject"> <div class="subject">
<kbd></kbd> + <kbd>K</kbd> <kbd></kbd> + <kbd></kbd> + <kbd>L</kbd>
</div> </div>
<div class="description"> <div class="description">
<p>Clear the current screen</p> <p>Clear the current screen</p>
</div> </div>
</div> </div>
<div class="help-item">
<div class="subject">
<kbd></kbd> + <kbd>K</kbd>
</div>
<div class="description">
<p>
Mark any text typed after this shortcut to be colored. After
hitting this shortcut, enter an integer in the
<code>0—15</code> range to select the desired color.
</p>
<p>
A color reference can be found
<a href="http://www.mirc.com/colors.html" target="_blank">here</a>.
</p>
</div>
</div>
<div class="help-item">
<div class="subject">
<kbd></kbd> + <kbd>B</kbd>
</div>
<div class="description">
<p>Mark all text typed after this shortcut as bold.</p>
</div>
</div>
<div class="help-item">
<div class="subject">
<kbd></kbd> + <kbd>U</kbd>
</div>
<div class="description">
<p>Mark all text typed after this shortcut as underlined.</p>
</div>
</div>
<div class="help-item">
<div class="subject">
<kbd></kbd> + <kbd>I</kbd>
</div>
<div class="description">
<p>Mark all text typed after this shortcut as italics.</p>
</div>
</div>
<div class="help-item">
<div class="subject">
<kbd></kbd> + <kbd>O</kbd>
</div>
<div class="description">
<p>
Mark all text typed after this shortcut to be reset to its
original formatting.
</p>
</div>
</div>
<h2>Commands</h2> <h2>Commands</h2>
<p>All commands can be autocompleted with <kbd>tab</kbd>.</p> <p>All commands can be autocompleted with <kbd>tab</kbd>.</p>
@ -463,7 +575,7 @@
<p> <p>
Send a <abbr title="Client-to-client protocol">CTCP</abbr> Send a <abbr title="Client-to-client protocol">CTCP</abbr>
request. Read more about this on request. Read more about this on
<a href="https://en.wikipedia.org/wiki/Client-to-client_protocol">the dedicated Wikipedia article</a>. <a href="https://en.wikipedia.org/wiki/Client-to-client_protocol" target="_blank">the dedicated Wikipedia article</a>.
</p> </p>
</div> </div>
</div> </div>

View File

@ -1300,6 +1300,7 @@ $(function() {
$(this).data("lastvalue", nick); $(this).data("lastvalue", nick);
}); });
(function HotkeysScope() {
Mousetrap.bind([ Mousetrap.bind([
"command+up", "command+up",
"command+down", "command+down",
@ -1325,7 +1326,7 @@ $(function() {
}); });
Mousetrap.bind([ Mousetrap.bind([
"command+k", "command+shift+l",
"ctrl+shift+l" "ctrl+shift+l"
], function(e) { ], function(e) {
if (e.target === input[0]) { if (e.target === input[0]) {
@ -1340,6 +1341,41 @@ $(function() {
contextMenuContainer.hide(); contextMenuContainer.hide();
}); });
var colorsHotkeys = {
k: "\x03",
b: "\x02",
u: "\x1F",
i: "\x1D",
o: "\x0F",
};
for (var hotkey in colorsHotkeys) {
Mousetrap.bind([
"command+" + hotkey,
"ctrl+" + hotkey
], function(e) {
e.preventDefault();
const cursorPosStart = input.prop("selectionStart");
const cursorPosEnd = input.prop("selectionEnd");
const value = input.val();
let newValue = value.substring(0, cursorPosStart) + colorsHotkeys[e.key];
if (cursorPosStart === cursorPosEnd) {
// If no text is selected, insert at cursor
newValue += value.substring(cursorPosEnd, value.length);
} else {
// If text is selected, insert formatting character at start and the end
newValue += value.substring(cursorPosStart, cursorPosEnd) + colorsHotkeys[e.key] + value.substring(cursorPosEnd, value.length);
}
input
.val(newValue)
.get(0).setSelectionRange(cursorPosStart + 1, cursorPosEnd + 1);
});
}
}());
setInterval(function() { setInterval(function() {
chat.find(".chan:not(.active)").each(function() { chat.find(".chan:not(.active)").each(function() {
var chan = $(this); var chan = $(this);