From 73ecf2cf190e73e6c7b664dbfb2c4d58777392a3 Mon Sep 17 00:00:00 2001 From: Jeremy Mahieu Date: Thu, 14 May 2020 19:48:49 +0200 Subject: [PATCH 1/4] Fix unable to use history when input bar empty --- js/inputbar.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/js/inputbar.js b/js/inputbar.js index 6aed63d..6947a05 100644 --- a/js/inputbar.js +++ b/js/inputbar.js @@ -632,9 +632,12 @@ weechat.directive('inputBar', function() { // Arrow up -> go up in history if ($event.type === "keydown" && code === 38 && document.activeElement === inputNode) { - caretPos = inputNode.selectionStart; - if (!$scope.command || $scope.command.slice(0, caretPos).indexOf("\n") !== -1) { - return false; + // In case of multiline we don't want to do this unless at the first line + if ($scope.command) { + caretPos = inputNode.selectionStart; + if ($scope.command.slice(0, caretPos).indexOf("\n") !== -1) { + return false; + } } $scope.command = models.getActiveBuffer().getHistoryUp($scope.command); // Set cursor to last position. Need 0ms timeout because browser sets cursor @@ -649,9 +652,12 @@ weechat.directive('inputBar', function() { // Arrow down -> go down in history if ($event.type === "keydown" && code === 40 && document.activeElement === inputNode) { - caretPos = inputNode.selectionStart; - if (!$scope.command || $scope.command.slice(caretPos).indexOf("\n") !== -1) { - return false; + // In case of multiline we don't want to do this + if ($scope.command) { + caretPos = inputNode.selectionStart; + if ( $scope.command.slice(caretPos).indexOf("\n") !== -1) { + return false; + } } $scope.command = models.getActiveBuffer().getHistoryDown($scope.command); // We don't need to set the cursor to the rightmost position here, the browser does that for us From 1e05a2d2090accb29fc98f3173e4ac8360d82acb Mon Sep 17 00:00:00 2001 From: Jeremy Mahieu Date: Thu, 14 May 2020 19:50:40 +0200 Subject: [PATCH 2/4] Improve comment --- js/inputbar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/inputbar.js b/js/inputbar.js index 6947a05..96e4c2f 100644 --- a/js/inputbar.js +++ b/js/inputbar.js @@ -652,7 +652,7 @@ weechat.directive('inputBar', function() { // Arrow down -> go down in history if ($event.type === "keydown" && code === 40 && document.activeElement === inputNode) { - // In case of multiline we don't want to do this + // In case of multiline we don't want to do this unless it's the last line if ($scope.command) { caretPos = inputNode.selectionStart; if ( $scope.command.slice(caretPos).indexOf("\n") !== -1) { From 5697105264da6fb51a6051650df3856f7b7e3440 Mon Sep 17 00:00:00 2001 From: Jeremy Mahieu Date: Mon, 18 May 2020 21:02:24 +0200 Subject: [PATCH 3/4] Set cursor at end fix for firefox --- js/inputbar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/inputbar.js b/js/inputbar.js index 96e4c2f..304bc93 100644 --- a/js/inputbar.js +++ b/js/inputbar.js @@ -646,7 +646,7 @@ weechat.directive('inputBar', function() { if ($scope.command) { inputNode.setSelectionRange($scope.command.length, $scope.command.length); } - }, 0); + }, 1); return true; } From 2fd9adfc9ad94707885ad59bb5d6fd79f3dda6fd Mon Sep 17 00:00:00 2001 From: Jeremy Mahieu Date: Mon, 18 May 2020 21:05:01 +0200 Subject: [PATCH 4/4] Correct comments --- js/inputbar.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/inputbar.js b/js/inputbar.js index 304bc93..d6ea251 100644 --- a/js/inputbar.js +++ b/js/inputbar.js @@ -640,8 +640,8 @@ weechat.directive('inputBar', function() { } } $scope.command = models.getActiveBuffer().getHistoryUp($scope.command); - // Set cursor to last position. Need 0ms timeout because browser sets cursor - // position to the beginning after this key handler returns. + // Set cursor to last position. Need 1ms (0ms works for chrome) timeout because + // browser sets cursor position to the beginning after this key handler returns. setTimeout(function() { if ($scope.command) { inputNode.setSelectionRange($scope.command.length, $scope.command.length);