Skip to content
Snippets Groups Projects
Commit 219ed994 authored by g0dil's avatar g0dil
Browse files

Utils/Termlib: Fix broken history handling

parent 67f3c1d9
No related branches found
No related tags found
No related merge requests found
......@@ -346,7 +346,7 @@ prefix_ void senf::term::LineEditor::accept()
if (enabled_)
newline();
hide();
pushHistory(text_);
pushHistory(text_, true);
callback_(text_);
clear();
}
......@@ -430,14 +430,16 @@ prefix_ void senf::term::LineEditor::insert(std::string const & text)
redisplay();
}
prefix_ void senf::term::LineEditor::pushHistory(std::string const & text)
prefix_ void senf::term::LineEditor::pushHistory(std::string const & text, bool accept)
{
if (! text.empty()
&& (accept || historyPoint_ == history_.size() || history_[historyPoint_] != text)
&& (history_.empty() || history_.back() != text)) {
history_.push_back(text);
while (history_.size() > MAX_HISTORY_SIZE)
history_.erase(history_.begin());
historyPoint_ = history_.size() - 1;
if (accept)
historyPoint_ = history_.size() - 1;
}
}
......
......@@ -256,7 +256,8 @@ namespace term {
///\name History
///\{
void pushHistory(std::string const & text); ///< Add string \a text to history
void pushHistory(std::string const & text, bool accept = false);
///< Add string \a text to history
void prevHistory(); ///< Switch to previous history entry
void nextHistory(); ///< Switch to next history entry
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment