Merge pull request #1672 from friarzen/master-historyjs-fix

Fix #1668 - up arrow key regression
This commit is contained in:
Griatch 2018-10-06 05:09:19 +02:00 committed by GitHub
commit dca73c707c

View file

@ -43,14 +43,6 @@ let history_plugin = (function () {
history_pos = 0;
}
//
// Go to the last history line
var end = function () {
// move to the end of the history stack
history_pos = 0;
return history[history.length -1];
}
//
// Add input to the scratch line
var scratch = function (input) {
@ -69,28 +61,17 @@ let history_plugin = (function () {
var history_entry = null;
var inputfield = $("#inputfield");
if (inputfield[0].selectionStart == inputfield.val().length) {
// Only process up/down arrow if cursor is at the end of the line.
if (code === 38) { // Arrow up
history_entry = back();
}
else if (code === 40) { // Arrow down
history_entry = fwd();
}
if (code === 38) { // Arrow up
history_entry = back();
}
else if (code === 40) { // Arrow down
history_entry = fwd();
}
if (history_entry !== null) {
// Doing a history navigation; replace the text in the input.
inputfield.val(history_entry);
}
else {
// Save the current contents of the input to the history scratch area.
setTimeout(function () {
// Need to wait until after the key-up to capture the value.
scratch(inputfield.val());
end();
}, 0);
}
return false;
}
@ -99,6 +80,7 @@ let history_plugin = (function () {
// Listen for onSend lines to add to history
var onSend = function (line) {
add(line);
return null; // we are not returning an altered input line
}
//