diff options
author | Stefan Dombrowski <stefan@uni-bonn.de> | 2010-08-31 23:15:04 +0200 |
---|---|---|
committer | Stefan Dombrowski <stefan@uni-bonn.de> | 2010-08-31 23:15:04 +0200 |
commit | fe08ffb9047bed67474aa8519051a0d4dcab98c5 (patch) | |
tree | 09d913c3259be04d514794cd420a9a450fc4a205 /src/gui | |
parent | f63a221850062da5b676c7dce258405f59486530 (diff) | |
download | mana-fe08ffb9047bed67474aa8519051a0d4dcab98c5.tar.gz mana-fe08ffb9047bed67474aa8519051a0d4dcab98c5.tar.bz2 mana-fe08ffb9047bed67474aa8519051a0d4dcab98c5.tar.xz mana-fe08ffb9047bed67474aa8519051a0d4dcab98c5.zip |
Fixing auto complete and chat history
Reviewed-by: Jaxad0127
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/widgets/textfield.cpp | 18 | ||||
-rw-r--r-- | src/gui/widgets/textfield.h | 4 |
2 files changed, 8 insertions, 14 deletions
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()); } } } diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h index 6e50f1e9..1963f9fa 100644 --- a/src/gui/widgets/textfield.h +++ b/src/gui/widgets/textfield.h @@ -57,8 +57,8 @@ struct TextHistory { void addEntry(const std::string &text) { history.push_back(text); } - bool matchesEntry(const std::string &text) - { return (*current) == text; } + bool matchesLastEntry(const std::string &text) + { return history.back() == text; } }; class AutoCompleteLister { |