Fixing a bug where clicking to the right of a character in a textbox...

...may select an invalid character, thus leading to a string
out-of-bounds error when another character is entered.

Enabled accented characters in textboxes, for Latin-1 charset.
This commit is contained in:
Philippe Plantier 2004-04-24 14:21:48 +00:00
parent 8690dfdfe3
commit 7b147faf57

View File

@ -198,7 +198,7 @@ void textbox::handle_event(const SDL_Event& event)
int pos = 0;
int distance = x;
for(int i = 1; i <= char_pos_.size(); ++i) {
for(int i = 1; i < char_pos_.size(); ++i) {
// Check individually each distance (if, one day, we support
// RTL languages, char_pos[c] may not be monotonous.)
if(abs(x - char_pos_[i]) < distance) {
@ -206,7 +206,7 @@ void textbox::handle_event(const SDL_Event& event)
distance = abs(x - char_pos_[i]);
}
}
cursor_ = pos;
if(grabmouse_)
@ -276,9 +276,13 @@ void textbox::handle_event(const SDL_Event& event)
}
}
const char character = static_cast<char>(key.unicode);
// const char character = static_cast<char>(key.unicode);
int character = key.unicode;
if(isgraph(character) || character == ' ') {
if(character != 0)
std::cerr << "Char: " << character << "\n";
if(/*isgraph(character) || character == ' '*/ character >= 32 && character != 127) {
changed = true;
if(is_selection())
erase_selection();