diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-07-29 19:27:18 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-07-29 19:27:18 (GMT) |
| commit | 011a65f793e37bd805d3aa6b2ca6daf1b7893c52 (patch) | |
| tree | d3b533907ef6292e85eb293d1529c1a174fbe9c4 /src/interface/Textbox.cpp | |
| parent | d138b2de544ab6ccdd7ec72bb5051e0bc437a1a9 (diff) | |
| download | powder-011a65f793e37bd805d3aa6b2ca6daf1b7893c52.zip powder-011a65f793e37bd805d3aa6b2ca6daf1b7893c52.tar.gz | |
Improvements to textbox, prevent selection loss on non modifying keypresses
Diffstat (limited to 'src/interface/Textbox.cpp')
| -rw-r--r-- | src/interface/Textbox.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/interface/Textbox.cpp b/src/interface/Textbox.cpp index f190322..29e36a3 100644 --- a/src/interface/Textbox.cpp +++ b/src/interface/Textbox.cpp @@ -254,17 +254,21 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool { case KEY_HOME: cursor = 0; + ClearSelection(); break; case KEY_END: cursor = backingText.length(); + ClearSelection(); break; case KEY_LEFT: if(cursor > 0) cursor--; + ClearSelection(); break; case KEY_RIGHT: if(cursor < backingText.length()) cursor++; + ClearSelection(); break; case KEY_DELETE: if(HasSelection()) @@ -283,6 +287,7 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool backingText.erase(cursor, 1); changed = true; } + ClearSelection(); break; case KEY_BACKSPACE: if(HasSelection()) @@ -307,6 +312,7 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool } changed = true; } + ClearSelection(); break; } if(CharacterValid(character)) @@ -332,8 +338,8 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool } cursor++; changed = true; + ClearSelection(); } - ClearSelection(); } catch(std::out_of_range &e) { @@ -350,8 +356,8 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool if(!backingText.length()) backingText = "0"; } - if(cursor >= backingText.length()) - cursor = backingText.length()-1; + if(cursor > backingText.length()) + cursor = backingText.length(); if(changed) { if(masked) |
