diff options
-rw-r--r-- | src/gui/windows/chatwindow.cpp | 18 | ||||
-rw-r--r-- | src/gui/windows/chatwindow.h | 2 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp index c6b3d0987..6c5219b01 100644 --- a/src/gui/windows/chatwindow.cpp +++ b/src/gui/windows/chatwindow.cpp @@ -728,6 +728,7 @@ void ChatWindow::keyPressed(KeyEvent &event) { // Move forward through the history const HistoryIterator prevHist = mCurHist++; + addCurrentToHistory(); if (mCurHist != mHistory.end()) { @@ -743,6 +744,8 @@ void ChatWindow::keyPressed(KeyEvent &event) } else if (!mChatInput->getText().empty()) { + if (addCurrentToHistory()) + mCurHist = mHistory.end(); mChatInput->setText(""); } } @@ -751,6 +754,7 @@ void ChatWindow::keyPressed(KeyEvent &event) { // Move backward through the history --mCurHist; + addCurrentToHistory(); mChatInput->setText(*mCurHist); mChatInput->setCaretPosition(static_cast<unsigned>( mChatInput->getText().length())); @@ -890,6 +894,20 @@ void ChatWindow::keyPressed(KeyEvent &event) #undef ifKey +bool ChatWindow::addCurrentToHistory() +{ + const std::string str = mChatInput->getText(); + if (str.empty()) + return false; + FOR_EACH (HistoryIterator, it, mHistory) + { + if (*it == str) + return false; + } + mHistory.push_back(str); + return true; +} + void ChatWindow::statChanged(const int id, const int oldVal1, const int oldVal2) diff --git a/src/gui/windows/chatwindow.h b/src/gui/windows/chatwindow.h index b90b15b45..d6b89fbd1 100644 --- a/src/gui/windows/chatwindow.h +++ b/src/gui/windows/chatwindow.h @@ -329,6 +329,8 @@ class ChatWindow final : public Window, void updateTabsMargin(); + bool addCurrentToHistory(); + typedef std::map<const std::string, WhisperTab*> TabMap; /** Manage whisper tabs */ TabMap mWhispers; |