From ea4de99e891895ca4881ec5bcf54711e0f8e7539 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 5 May 2017 21:39:06 +0200 Subject: [PATCH] Fix Ctrl+W when the cursor follows a space. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- js/inputbar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/inputbar.js b/js/inputbar.js index c77bcf4..725f9f0 100644 --- a/js/inputbar.js +++ b/js/inputbar.js @@ -467,7 +467,7 @@ weechat.directive('inputBar', function() { // Ctrl-w } else if (code == 87) { 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); setTimeout(function() { inputNode.setSelectionRange(lastSpace, lastSpace);