From: g0dil Date: Mon, 9 Feb 2009 15:38:23 +0000 (+0000) Subject: Utils/Termlib: Fix broken history handling X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=8da6e83b001f0ae8383af7eb4b3e3a079178a777;p=senf.git Utils/Termlib: Fix broken history handling git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1109 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Utils/Termlib/Editor.cc b/Utils/Termlib/Editor.cc index 8f434a6..ce6a3fb 100644 --- a/Utils/Termlib/Editor.cc +++ b/Utils/Termlib/Editor.cc @@ -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; } } diff --git a/Utils/Termlib/Editor.hh b/Utils/Termlib/Editor.hh index ead9a06..bacfeff 100644 --- a/Utils/Termlib/Editor.hh +++ b/Utils/Termlib/Editor.hh @@ -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