From 10bbb63929bce952d38d0431e2088db4fa32ddbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Sat, 5 Apr 2014 22:18:48 +0200 Subject: [PATCH] Move cursor to end when navigating history Fixes #244 --- js/glowingbear.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/js/glowingbear.js b/js/glowingbear.js index 80a6094..7e68def 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -1291,12 +1291,18 @@ weechat.directive('inputBar', function() { // Arrow up -> go up in history if (code === 38) { inputNode.value = models.getActiveBuffer().getHistoryUp(inputNode.value); + // Set cursor to last position. Need 0ms timeout because browser sets cursor + // position to the beginning after this key handler returns. + setTimeout(function() { + inputNode.setSelectionRange(inputNode.value.length, inputNode.value.length); + }, 0); return true; } // Arrow down -> go down in history if (code === 40) { inputNode.value = models.getActiveBuffer().getHistoryDown(inputNode.value); + // We don't need to set the cursor to the rightmost position here, the browser does that for us return true; } };