summaryrefslogtreecommitdiff
path: root/src/gui/windows/chatwindow.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-05-31 13:13:47 +0300
committerAndrei Karas <akaras@inbox.ru>2014-05-31 13:13:47 +0300
commit1072eecf0e9e9140796d24f82d077199b2a1d9e6 (patch)
tree2c90f4f56a735cb184e90519650d7e2ac1db6eb9 /src/gui/windows/chatwindow.cpp
parentc0197404a15a3937ef3cd21f48a09e691a96518f (diff)
downloadplus-1072eecf0e9e9140796d24f82d077199b2a1d9e6.tar.gz
plus-1072eecf0e9e9140796d24f82d077199b2a1d9e6.tar.bz2
plus-1072eecf0e9e9140796d24f82d077199b2a1d9e6.tar.xz
plus-1072eecf0e9e9140796d24f82d077199b2a1d9e6.zip
Add to chat history enteerd text if was pressed up or down key.
Diffstat (limited to 'src/gui/windows/chatwindow.cpp')
-rw-r--r--src/gui/windows/chatwindow.cpp18
1 files changed, 18 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)