From 1072eecf0e9e9140796d24f82d077199b2a1d9e6 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 31 May 2014 13:13:47 +0300 Subject: Add to chat history enteerd text if was pressed up or down key. --- src/gui/windows/chatwindow.cpp | 18 ++++++++++++++++++ src/gui/windows/chatwindow.h | 2 ++ 2 files changed, 20 insertions(+) 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( 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 TabMap; /** Manage whisper tabs */ TabMap mWhispers; -- cgit v1.2.3-70-g09d2