Implement color hotkeys
This commit is contained in:
parent
2f1cc97631
commit
f2e43b84be
@ -1284,45 +1284,81 @@ $(function() {
|
|||||||
forms.find(".username").val(nick);
|
forms.find(".username").val(nick);
|
||||||
});
|
});
|
||||||
|
|
||||||
Mousetrap.bind([
|
(function HotkeysScope() {
|
||||||
"command+up",
|
Mousetrap.bind([
|
||||||
"command+down",
|
"command+up",
|
||||||
"ctrl+up",
|
"command+down",
|
||||||
"ctrl+down"
|
"ctrl+up",
|
||||||
], function(e, keys) {
|
"ctrl+down"
|
||||||
var channels = sidebar.find(".chan");
|
], function(e, keys) {
|
||||||
var index = channels.index(channels.filter(".active"));
|
var channels = sidebar.find(".chan");
|
||||||
var direction = keys.split("+").pop();
|
var index = channels.index(channels.filter(".active"));
|
||||||
switch (direction) {
|
var direction = keys.split("+").pop();
|
||||||
case "up":
|
switch (direction) {
|
||||||
// Loop
|
case "up":
|
||||||
var upTarget = (channels.length + (index - 1 + channels.length)) % channels.length;
|
// Loop
|
||||||
channels.eq(upTarget).click();
|
var upTarget = (channels.length + (index - 1 + channels.length)) % channels.length;
|
||||||
break;
|
channels.eq(upTarget).click();
|
||||||
|
break;
|
||||||
|
|
||||||
case "down":
|
case "down":
|
||||||
// Loop
|
// Loop
|
||||||
var downTarget = (channels.length + (index + 1 + channels.length)) % channels.length;
|
var downTarget = (channels.length + (index + 1 + channels.length)) % channels.length;
|
||||||
channels.eq(downTarget).click();
|
channels.eq(downTarget).click();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Mousetrap.bind([
|
||||||
|
"command+shift+l",
|
||||||
|
"ctrl+shift+l"
|
||||||
|
], function(e) {
|
||||||
|
if (e.target === input[0]) {
|
||||||
|
clear();
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Mousetrap.bind([
|
||||||
|
"escape"
|
||||||
|
], function() {
|
||||||
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
}());
|
||||||
|
|
||||||
Mousetrap.bind([
|
|
||||||
"command+k",
|
|
||||||
"ctrl+shift+l"
|
|
||||||
], function(e) {
|
|
||||||
if (e.target === input[0]) {
|
|
||||||
clear();
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Mousetrap.bind([
|
|
||||||
"escape"
|
|
||||||
], function() {
|
|
||||||
contextMenuContainer.hide();
|
|
||||||
});
|
|
||||||
|
|
||||||
setInterval(function() {
|
setInterval(function() {
|
||||||
chat.find(".chan:not(.active)").each(function() {
|
chat.find(".chan:not(.active)").each(function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user