From 4081b18ed218dc71e6cabb0343a2cafa46a43048 Mon Sep 17 00:00:00 2001 From: Tor Hveem Date: Sun, 20 Jul 2014 12:21:46 +0200 Subject: [PATCH 1/2] Add some emacs keybindings. Fixes #371 Add the most commonly used emacs/readline keybindings to input field and document them. Also change the wording on some of the old descritions to clarify intent. --- index.html | 8 +++++--- js/glowingbear.js | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 19d3117..f8cff93 100644 --- a/index.html +++ b/index.html @@ -114,12 +114,14 @@ diff --git a/js/glowingbear.js b/js/glowingbear.js index e0cf16f..fcae26b 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -1517,12 +1517,45 @@ weechat.directive('inputBar', function() { } // Enter to submit, shift-enter for newline - // if (code == 13 && !$event.shiftKey && document.activeElement === inputNode) { $event.preventDefault(); $scope.sendMessage(); return true; } + // Some readline keybindings + if ($event.ctrlKey && !$event.altKey && !$event.shiftKey && document.activeElement === inputNode) { + // Ctrl-a + if (code == 65) { + inputNode.setSelectionRange(0, 0); + // Ctrl-e + } else if (code == 69) { + inputNode.setSelectionRange($scope.command.length, $scope.command.length); + // Ctrl-u + } else if (code == 85) { + $scope.command = $scope.command.slice(caretPos); + setTimeout(function() { + inputNode.setSelectionRange(0, 0); + }); + // Ctrl-k + } else if (code == 75) { + $scope.command = $scope.command.slice(0, caretPos); + setTimeout(function() { + inputNode.setSelectionRange($scope.command.length, $scope.command.length); + }); + // Ctrl-w + } else if (code == 87) { + var trimmedValue = $scope.command.slice(0, caretPos); + var lastSpace = trimmedValue.lastIndexOf(' ') + 1; + $scope.command = $scope.command.slice(0, lastSpace) + $scope.command.slice(caretPos, $scope.command.length); + setTimeout(function() { + inputNode.setSelectionRange(lastSpace, lastSpace); + }); + } else { + return false; + } + $event.preventDefault(); + return true; + } }; } }; From 99cf794efc5c73dea628f65ec9357e8cc1c992f9 Mon Sep 17 00:00:00 2001 From: Tor Hveem Date: Sun, 20 Jul 2014 13:21:39 +0200 Subject: [PATCH 2/2] Use title tag to explain keybindings --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index f8cff93..146b64f 100644 --- a/index.html +++ b/index.html @@ -121,7 +121,7 @@
  • Esc-Esc: disconnect (double-tap)
  • Arrow keys: history navigation
  • Tab key: nick complete
  • -
  • The following readline/emacs style keybindings works: Ctrl-a, Ctrl-e, Ctrl-u, Ctrl-k, Ctrl-w
  • +
  • The following readline/emacs style keybindings works: Ctrl-a, Ctrl-e, Ctrl-u, Ctrl-k, Ctrl-w