From f2e43b84bedf7542b68c9b87668ab1372b9ab233 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sat, 17 Dec 2016 22:03:12 +0200 Subject: [PATCH 1/2] Implement color hotkeys --- client/js/lounge.js | 110 +++++++++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 37 deletions(-) diff --git a/client/js/lounge.js b/client/js/lounge.js index 81275fbd..0d2a08ec 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -1284,45 +1284,81 @@ $(function() { forms.find(".username").val(nick); }); - Mousetrap.bind([ - "command+up", - "command+down", - "ctrl+up", - "ctrl+down" - ], function(e, keys) { - var channels = sidebar.find(".chan"); - var index = channels.index(channels.filter(".active")); - var direction = keys.split("+").pop(); - switch (direction) { - case "up": - // Loop - var upTarget = (channels.length + (index - 1 + channels.length)) % channels.length; - channels.eq(upTarget).click(); - break; + (function HotkeysScope() { + Mousetrap.bind([ + "command+up", + "command+down", + "ctrl+up", + "ctrl+down" + ], function(e, keys) { + var channels = sidebar.find(".chan"); + var index = channels.index(channels.filter(".active")); + var direction = keys.split("+").pop(); + switch (direction) { + case "up": + // Loop + var upTarget = (channels.length + (index - 1 + channels.length)) % channels.length; + channels.eq(upTarget).click(); + break; - case "down": - // Loop - var downTarget = (channels.length + (index + 1 + channels.length)) % channels.length; - channels.eq(downTarget).click(); - break; + case "down": + // Loop + var downTarget = (channels.length + (index + 1 + channels.length)) % channels.length; + channels.eq(downTarget).click(); + 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() { chat.find(".chan:not(.active)").each(function() { From 8ef99d7ad831beedb8136edaf5f83626d76208b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Mon, 13 Mar 2017 01:58:39 -0400 Subject: [PATCH 2/2] Add shortcuts for new formatting in help window --- client/index.html | 116 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 2 deletions(-) diff --git a/client/index.html b/client/index.html index 0ec349a6..192a4085 100644 --- a/client/index.html +++ b/client/index.html @@ -390,6 +390,62 @@ +
+
+ Ctrl + K +
+
+

+ Mark any text typed after this shortcut to be colored. After + hitting this shortcut, enter an integer in the + 0—15 range to select the desired color. +

+

+ A color reference can be found + here. +

+
+
+ +
+
+ Ctrl + B +
+
+

Mark all text typed after this shortcut as bold.

+
+
+ +
+
+ Ctrl + U +
+
+

Mark all text typed after this shortcut as underlined.

+
+
+ +
+
+ Ctrl + I +
+
+

Mark all text typed after this shortcut as italics.

+
+
+ +
+
+ Ctrl + O +
+
+

+ Mark all text typed after this shortcut to be reset to its + original formatting. +

+
+
+

On macOS

@@ -403,13 +459,69 @@
- + K + + + L

Clear the current screen

+
+
+ + K +
+
+

+ Mark any text typed after this shortcut to be colored. After + hitting this shortcut, enter an integer in the + 0—15 range to select the desired color. +

+

+ A color reference can be found + here. +

+
+
+ +
+
+ + B +
+
+

Mark all text typed after this shortcut as bold.

+
+
+ +
+
+ + U +
+
+

Mark all text typed after this shortcut as underlined.

+
+
+ +
+
+ + I +
+
+

Mark all text typed after this shortcut as italics.

+
+
+ +
+
+ + O +
+
+

+ Mark all text typed after this shortcut to be reset to its + original formatting. +

+
+
+

Commands

@@ -461,7 +573,7 @@

Send a CTCP request. Read more about this on - the dedicated Wikipedia article. + the dedicated Wikipedia article.