Merge pull request #376 from glowing-bear/readline

fix keybindings relying on caretPos
This commit is contained in:
Tor Hveem 2014-07-21 16:42:13 +02:00
commit f95a84a93d
2 changed files with 24 additions and 5 deletions

View file

@ -124,10 +124,10 @@
<li>ALT-a: Focus on next buffer with activity</li> <li>ALT-a: Focus on next buffer with activity</li>
<li>ALT-&lt;: Switch to previous active buffer</li> <li>ALT-&lt;: Switch to previous active buffer</li>
<li>ALT-g: Focus on buffer list filter</li> <li>ALT-g: Focus on buffer list filter</li>
<li>Esc-Esc: disconnect (double-tap)</li> <li>Esc-Esc: Disconnect (double-tap)</li>
<li>Arrow keys: history navigation</li> <li>Arrow keys: Navigate history</li>
<li>Tab key: nick complete</li> <li>Tab key: Complete nick</li>
<li>The following readline/emacs style keybindings works: <span title="Move cursor to beginning of line">Ctrl-a</span>, <span title="Move cursor to te end of the line">Ctrl-e</span>, <span title="Delete from cursor to beginning of the line">Ctrl-u</span>, <span title="Delete from cursor to the end of the line">Ctrl-k</span>, <span title="Delete from cursor to previous space">Ctrl-w</span></li> <li>The following readline/emacs style keybindings can be enabled with a setting: <span title="Move cursor to beginning of line">Ctrl-a</span>, <span title="Move cursor to te end of the line">Ctrl-e</span>, <span title="Delete from cursor to beginning of the line">Ctrl-u</span>, <span title="Delete from cursor to the end of the line">Ctrl-k</span>, <span title="Delete from cursor to previous space">Ctrl-w</span></li>
</ul> </ul>
</div> </div>
</div> </div>
@ -370,6 +370,16 @@ $ openssl req -nodes -newkey rsa:4096 -keyout relay.pem -x509 -days 365 -out rel
</div> </div>
</form> </form>
</li> </li>
<li>
<form class="form-inline" role="form">
<div class="checkbox">
<label>
<input type="checkbox" ng-model="readlineBindings">
Enable common readline keybindings in input bar
</label>
</div>
</form>
</li>
<li> <li>
<form class="form-inline" role="form"> <form class="form-inline" role="form">
<div class="checkbox"> <div class="checkbox">

View file

@ -869,6 +869,8 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$store.bind($scope, "fontfamily", getClassStyle('monospace', 'fontFamily')); $store.bind($scope, "fontfamily", getClassStyle('monospace', 'fontFamily'));
// Save setting for font size // Save setting for font size
$store.bind($scope, "fontsize", getClassStyle('monospace', 'fontSize')); $store.bind($scope, "fontsize", getClassStyle('monospace', 'fontSize'));
// Save setting for readline keybindings
$store.bind($scope, "readlineBindings", false);
// Save setting for displaying embeds in rootScope so it can be used from service // Save setting for displaying embeds in rootScope so it can be used from service
$rootScope.visible = $scope.noembed === false; $rootScope.visible = $scope.noembed === false;
@ -949,6 +951,11 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$scope.$watch('fontsize', function() { $scope.$watch('fontsize', function() {
changeClassStyle('monospace', 'fontSize', $scope.fontsize); changeClassStyle('monospace', 'fontSize', $scope.fontsize);
}); });
// Crude scoping hack. The keypress listener does not live in the same scope as
// the checkbox, so we need to transfer this between scopes here.
$scope.$watch('readlineBindings', function() {
$rootScope.readlineBindings = $scope.readlineBindings;
});
$scope.setActiveBuffer = function(bufferId, key) { $scope.setActiveBuffer = function(bufferId, key) {
// If we are on mobile we need to collapse the menu on sidebar clicks // If we are on mobile we need to collapse the menu on sidebar clicks
@ -1533,7 +1540,9 @@ weechat.directive('inputBar', function() {
return true; return true;
} }
// Some readline keybindings // Some readline keybindings
if ($event.ctrlKey && !$event.altKey && !$event.shiftKey && document.activeElement === inputNode) { if ($rootScope.readlineBindings && $event.ctrlKey && !$event.altKey && !$event.shiftKey && document.activeElement === inputNode) {
// get current caret position
var caretPos = inputNode.selectionStart;
// Ctrl-a // Ctrl-a
if (code == 65) { if (code == 65) {
inputNode.setSelectionRange(0, 0); inputNode.setSelectionRange(0, 0);