Utils/Termlib: Fix broken history handling
g0dil [Mon, 9 Feb 2009 15:38:23 +0000 (15:38 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1109 270642c3-0616-0410-b53a-bc976706d245

Utils/Termlib/Editor.cc
Utils/Termlib/Editor.hh

index 8f434a6..ce6a3fb 100644 (file)
@@ -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;
     }
 }
 
index ead9a06..bacfeff 100644 (file)
@@ -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