Fix Ctrl+W when the cursor follows a space.

This key binding does "Delete from cursor to previous space".
When the text before the cursor was `some example`,
it would find the space after "some" and delete "example".
When hitting Ctrl+W *again*, it would find the same space again…
and delete nothing.

This changes the code to ignore trailing spaces before the cursor
for the purspose of finding the previous space,
so that something (if at all possible) is always deleted.
This commit is contained in:
Simon Sapin 2017-05-05 21:39:06 +02:00
parent eaffb17c5a
commit ea4de99e89

View file

@ -467,7 +467,7 @@ weechat.directive('inputBar', function() {
// Ctrl-w // Ctrl-w
} else if (code == 87) { } else if (code == 87) {
var trimmedValue = $scope.command.slice(0, caretPos); var trimmedValue = $scope.command.slice(0, caretPos);
var lastSpace = trimmedValue.lastIndexOf(' ') + 1; var lastSpace = trimmedValue.replace(/ +$/, '').lastIndexOf(' ') + 1;
$scope.command = $scope.command.slice(0, lastSpace) + $scope.command.slice(caretPos, $scope.command.length); $scope.command = $scope.command.slice(0, lastSpace) + $scope.command.slice(caretPos, $scope.command.length);
setTimeout(function() { setTimeout(function() {
inputNode.setSelectionRange(lastSpace, lastSpace); inputNode.setSelectionRange(lastSpace, lastSpace);