diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-08-02 22:58:25 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-08-02 22:58:25 +0300 |
commit | e1ec49e1934dfc25f21af7b9fa0a8f06fbea8aa3 (patch) | |
tree | 90ba22726db9411255afa5d878fe2b47702c9427 | |
parent | 82194116950eb6977eca992df48fb265e4b5df6c (diff) | |
download | manaverse-e1ec49e1934dfc25f21af7b9fa0a8f06fbea8aa3.tar.gz manaverse-e1ec49e1934dfc25f21af7b9fa0a8f06fbea8aa3.tar.bz2 manaverse-e1ec49e1934dfc25f21af7b9fa0a8f06fbea8aa3.tar.xz manaverse-e1ec49e1934dfc25f21af7b9fa0a8f06fbea8aa3.zip |
Add ctrl key combination to all text fields.
New keys: Ctrl+b,d,e,f,h,k,u,w
Working like in most text editors.
-rw-r--r-- | src/gui/widgets/textfield.cpp | 48 | ||||
-rw-r--r-- | src/utils/stringutils.cpp | 12 | ||||
-rw-r--r-- | src/utils/stringutils.h | 2 |
3 files changed, 52 insertions, 10 deletions
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 30d409bf7..d3108a77f 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -35,6 +35,7 @@ #include "utils/copynpaste.h" #include "utils/dtor.h" +#include "utils/stringutils.h" #include <guichan/font.hpp> @@ -224,6 +225,7 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) switch (val) { + case 2: // Ctrl+b case Key::LEFT: { while (mCaretPosition > 0) @@ -234,6 +236,7 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) } } break; + case 6: // Ctrl+f case Key::RIGHT: { unsigned sz = static_cast<unsigned>(mText.size()); @@ -248,6 +251,7 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) } } break; + case 4: // Ctrl+d case Key::DELETE: { unsigned sz = static_cast<unsigned>(mText.size()); @@ -263,17 +267,10 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) } } break; + case 8: // Ctrl+h case Key::BACKSPACE: - { - while (mCaretPosition > 0) - { - --mCaretPosition; - int v = mText[mCaretPosition]; - mText.erase(mCaretPosition, 1); - if ((v & 192) != 128) - break; - } - } break; + deleteCharLeft(mText, &mCaretPosition); + break; case Key::ENTER: distributeActionEvent(); @@ -292,6 +289,24 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) return; break; + case 5: // Ctrl+e + mCaretPosition = mText.size(); + break; + + case 11: // Ctrl+k + mText = mText.substr(0, mCaretPosition); + break; +// case 16: // Ctrl+p +// break; + + case 21: // Ctrl+u + if (mCaretPosition > 0) + { + mText = mText.substr(mCaretPosition); + mCaretPosition = 0; + } + break; + case 22: // Control code 22, SYNCHRONOUS IDLE, sent on Ctrl+v // hack to prevent paste key sticking if (mLastEventPaste && mLastEventPaste > cur_time) @@ -299,6 +314,19 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) handlePaste(); mLastEventPaste = cur_time + 2; break; + + case 23: // Ctrl+w + while (mCaretPosition > 0) + { + deleteCharLeft(mText, &mCaretPosition); + if (mCaretPosition > 0 && isWordSeparator( + mText[mCaretPosition - 1])) + { + break; + } + } + break; + default: break; } diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index ad2e52965..13170092e 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -499,3 +499,15 @@ std::string stringToHexPath(const std::string &str) hex += strprintf("%%%2x", (int)str[f]); return hex; } + +void deleteCharLeft(std::string &str, unsigned *pos) +{ + while (*pos > 0) + { + (*pos)--; + int v = str[*pos]; + str.erase(*pos, 1); + if ((v & 192) != 128) + break; + } +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 4693b5425..94747d2fe 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -188,4 +188,6 @@ std::list<std::string> unpackList(const std::string &str); std::string stringToHexPath(const std::string &str); +void deleteCharLeft(std::string &str, unsigned *pos); + #endif // UTILS_STRINGUTILS_H |