Fix unable to use history when input bar empty

codeql
Jeremy Mahieu 5 years ago
parent 700f322273
commit 73ecf2cf19
  1. 10
      js/inputbar.js

@ -632,10 +632,13 @@ weechat.directive('inputBar', function() {
// Arrow up -> go up in history // Arrow up -> go up in history
if ($event.type === "keydown" && code === 38 && document.activeElement === inputNode) { if ($event.type === "keydown" && code === 38 && document.activeElement === inputNode) {
// In case of multiline we don't want to do this unless at the first line
if ($scope.command) {
caretPos = inputNode.selectionStart; caretPos = inputNode.selectionStart;
if (!$scope.command || $scope.command.slice(0, caretPos).indexOf("\n") !== -1) { if ($scope.command.slice(0, caretPos).indexOf("\n") !== -1) {
return false; return false;
} }
}
$scope.command = models.getActiveBuffer().getHistoryUp($scope.command); $scope.command = models.getActiveBuffer().getHistoryUp($scope.command);
// Set cursor to last position. Need 0ms timeout because browser sets cursor // Set cursor to last position. Need 0ms timeout because browser sets cursor
// position to the beginning after this key handler returns. // position to the beginning after this key handler returns.
@ -649,10 +652,13 @@ weechat.directive('inputBar', function() {
// Arrow down -> go down in history // Arrow down -> go down in history
if ($event.type === "keydown" && code === 40 && document.activeElement === inputNode) { if ($event.type === "keydown" && code === 40 && document.activeElement === inputNode) {
// In case of multiline we don't want to do this
if ($scope.command) {
caretPos = inputNode.selectionStart; caretPos = inputNode.selectionStart;
if (!$scope.command || $scope.command.slice(caretPos).indexOf("\n") !== -1) { if ( $scope.command.slice(caretPos).indexOf("\n") !== -1) {
return false; return false;
} }
}
$scope.command = models.getActiveBuffer().getHistoryDown($scope.command); $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 // We don't need to set the cursor to the rightmost position here, the browser does that for us
return true; return true;

Loading…
Cancel
Save