summaryrefslogtreecommitdiff
path: root/src/gui/chat.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-05-09 19:33:22 +0200
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-05-09 19:36:15 +0200
commit3dacb9b09622375d35d704c8ac9d7039d506026f (patch)
treeebc9dd04955cee5d394403b754c150b7c2260f3b /src/gui/chat.cpp
parent3074acf977841492b2378b5542bc3d755cf0a227 (diff)
downloadmana-client-3dacb9b09622375d35d704c8ac9d7039d506026f.tar.gz
mana-client-3dacb9b09622375d35d704c8ac9d7039d506026f.tar.bz2
mana-client-3dacb9b09622375d35d704c8ac9d7039d506026f.tar.xz
mana-client-3dacb9b09622375d35d704c8ac9d7039d506026f.zip
Insert player and item names at caret position instead of at the end
An improvement based on the 0.0.28.Q version.
Diffstat (limited to 'src/gui/chat.cpp')
-rw-r--r--src/gui/chat.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 3d0cb766..11a327d8 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -44,6 +44,8 @@
#include <guichan/focushandler.hpp>
#include <guichan/focuslistener.hpp>
+#include <sstream>
+
/**
* The chat input hides when it loses focus. It is also invisible by default.
*/
@@ -336,7 +338,7 @@ void ChatWindow::doPresent()
time(&t);
// Format the time string properly
- std::stringstream timeStr;
+ std::ostringstream timeStr;
timeStr << "[" << ((((t / 60) / 60) % 24 < 10) ? "0" : "")
<< (int) (((t / 60) / 60) % 24)
<< ":" << (((t / 60) % 60 < 10) ? "0" : "")
@@ -359,7 +361,8 @@ void ChatWindow::scroll(int amount)
return;
ChatTab *tab = getFocused();
- if (tab) tab->scroll(amount);
+ if (tab)
+ tab->scroll(amount);
}
void ChatWindow::keyPressed(gcn::KeyEvent &event)
@@ -397,16 +400,24 @@ void ChatWindow::keyPressed(gcn::KeyEvent &event)
}
}
-void ChatWindow::addInputText(std::string input_str)
+void ChatWindow::addInputText(const std::string &text)
{
- mChatInput->setText(mChatInput->getText() + input_str + " ");
- requestChatFocus();
+ const int caretPos = mChatInput->getCaretPosition();
+ const std::string inputText = mChatInput->getText();
+
+ std::ostringstream ss;
+ ss << inputText.substr(0, caretPos) << text << " ";
+ ss << inputText.substr(caretPos);
+
+ mChatInput->setText(ss.str());
+ mChatInput->setCaretPosition(caretPos + text.length() + 1);
+ requestChatFocus();
}
void ChatWindow::addItemText(const std::string &item)
{
std::ostringstream text;
- text << "[" << item << "] ";
+ text << "[" << item << "]";
addInputText(text.str());
}