From fe08ffb9047bed67474aa8519051a0d4dcab98c5 Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Tue, 31 Aug 2010 23:15:04 +0200 Subject: Fixing auto complete and chat history Reviewed-by: Jaxad0127 --- src/gui/widgets/textfield.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/gui/widgets/textfield.cpp') diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 3e02be98..cffda1e3 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -276,10 +276,8 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) case Key::ENTER: if (mHistory) { - mHistory->toEnd(); - // If the input is different from previous, put it in the history - if (mHistory->empty() || !mHistory->matchesEntry(getText())) + if (mHistory->empty() || !mHistory->matchesLastEntry(getText())) { mHistory->addEntry(getText()); } @@ -317,23 +315,23 @@ void TextField::autoComplete() { if (mAutoComplete && mText.size() > 0) { - int caretPos = getCaretPosition(); + const int caretPos = getCaretPosition(); int startName = 0; const std::string inputText = getText(); std::string name = inputText.substr(0, caretPos); std::string newName(""); - for (int f = caretPos - 1; f > -1; f --) + for (int f = caretPos - 1; f > -1; f--) { if (isWordSeparator(inputText[f])) { startName = f + 1; - name = inputText.substr(f + 1, caretPos - f); + name = inputText.substr(f + 1, caretPos - startName); break; } } - if (caretPos - 1 + 1 != startName) + if (caretPos == startName) return; @@ -375,11 +373,7 @@ void TextField::autoComplete() + inputText.substr(caretPos, inputText.length() - caretPos)); - if (startName > 0) - setCaretPosition(caretPos - name.length() + newName.length() - + 1); - else - setCaretPosition(caretPos - name.length() + newName.length()); + setCaretPosition(caretPos - name.length() + newName.length()); } } } -- cgit v1.2.3-70-g09d2