fixed history scrolling

This commit is contained in:
Thomas Jentzsch 2021-05-14 09:32:03 +02:00
parent cabc56b155
commit 0dc0ff9d37
2 changed files with 7 additions and 10 deletions

View File

@ -556,15 +556,13 @@ void PromptWidget::textPaste()
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int PromptWidget::historyDir(int& index, int direction, bool promptSpace) int PromptWidget::historyDir(int& index, int direction)
{ {
int historySize = int(_history.size()) + (promptSpace ? 1 : 0);
index += direction; index += direction;
if(index < 0) if(index < 0)
index += historySize; index += int(_history.size());
else else
index %= historySize; index %= int(_history.size());
return index; return index;
} }
@ -620,13 +618,12 @@ bool PromptWidget::historyScroll(int direction)
if(_history.size() == 0) if(_history.size() == 0)
return false; return false;
// add current input temporarily to history
if(_historyLine == 0) if(_historyLine == 0)
{
historyAdd(getLine()); historyAdd(getLine());
}
// Advance to the next/prev line in the history // Advance to the next/prev line in the history
historyDir(_historyLine, direction, _history.size() < kHistorySize); historyDir(_historyLine, direction);
// Search the history using the original input // Search the history using the original input
do do
@ -639,7 +636,7 @@ bool PromptWidget::historyScroll(int direction)
break; break;
// Advance to the next/prev line in the history // Advance to the next/prev line in the history
historyDir(_historyLine, direction, _history.size() < kHistorySize); historyDir(_historyLine, direction);
} }
while(_historyLine); // If _historyLine == 0, nothing was found while(_historyLine); // If _historyLine == 0, nothing was found

View File

@ -133,7 +133,7 @@ class PromptWidget : public Widget, public CommandSender
bool _firstTime{true}; bool _firstTime{true};
bool _exitedEarly{false}; bool _exitedEarly{false};
int historyDir(int& index, int direction, bool promptSpace = false); int historyDir(int& index, int direction);
void historyAdd(const string& entry); void historyAdd(const string& entry);
private: private: