diff options
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/menu_button.cpp | 2 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 104 |
2 files changed, 53 insertions, 53 deletions
diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index fe76b16460..57aa72b7d0 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -55,7 +55,6 @@ void MenuButton::pressed() { popup->set_size(Size2(size.width, 0)); popup->set_parent_rect(Rect2(Point2(gp - popup->get_global_position()), get_size())); popup->popup(); - popup->call_deferred("grab_click_focus"); popup->set_invalidate_click_until_motion(); } @@ -112,6 +111,7 @@ MenuButton::MenuButton() { popup->hide(); add_child(popup); popup->set_as_toplevel(true); + connect("button_up", popup, "call_deferred", make_binds("grab_click_focus")); set_process_unhandled_key_input(true); set_action_mode(ACTION_MODE_BUTTON_PRESS); } diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 8baca50d32..d604738da1 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -49,6 +49,10 @@ static bool _is_symbol(CharType c) { return c != '_' && ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~') || c == '\t' || c == ' '); } +static bool _is_whitespace(CharType c) { + return c == '\t' || c == ' '; +} + static bool _is_char(CharType c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'; @@ -2096,45 +2100,43 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { break; #ifdef APPLE_STYLE_KEYS - if (k->get_alt()) { + if (k->get_alt() && cursor.column > 1) { #else if (k->get_alt()) { scancode_handled = false; break; - } else if (k->get_command()) { + } else if (k->get_command() && cursor.column > 1) { #endif int line = cursor.line; int column = cursor.column; - bool prev_char = false; - bool only_whitespace = true; - - while (only_whitespace && line > 0) { - - while (column > 0) { - CharType c = text[line][column - 1]; - - if (c != '\t' && c != ' ') { - only_whitespace = false; - break; - } + // check if we are removing a single whitespace, if so remove it and the next char type + // else we just remove the whitespace + bool only_whitespace = false; + if (_is_whitespace(text[line][column - 1]) && _is_whitespace(text[line][column - 2])) { + only_whitespace = true; + } else if (_is_whitespace(text[line][column - 1])) { + // remove the single whitespace + column--; + } - column--; - } + // check if its a text char + bool only_char = (_is_text_char(text[line][column - 1]) && !only_whitespace); - if (only_whitespace) { - line--; - column = text[line].length(); - } - } + // if its not whitespace or char then symbol. + bool only_symbols = !(only_whitespace || only_char); while (column > 0) { - bool ischar = _is_text_char(text[line][column - 1]); + bool is_whitespace = _is_whitespace(text[line][column - 1]); + bool is_text_char = _is_text_char(text[line][column - 1]); - if (prev_char && !ischar) + if (only_whitespace && !is_whitespace) { break; - - prev_char = ischar; + } else if (only_char && !is_text_char) { + break; + } else if (only_symbols && (is_whitespace || is_text_char)) { + break; + } column--; } @@ -2356,52 +2358,50 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { int next_column; #ifdef APPLE_STYLE_KEYS - if (k->get_alt()) { + if (k->get_alt() && cursor.column < curline_len - 1) { #else if (k->get_alt()) { scancode_handled = false; break; - } else if (k->get_command()) { + } else if (k->get_command() && cursor.column < curline_len - 1) { #endif - int last_line = text.size() - 1; int line = cursor.line; int column = cursor.column; - bool prev_char = false; - bool only_whitespace = true; - - while (only_whitespace && line < last_line) { - - while (column < text[line].length()) { - CharType c = text[line][column]; - - if (c != '\t' && c != ' ') { - only_whitespace = false; - break; - } - - column++; - } - - if (only_whitespace) { - line++; - column = 0; - } + // check if we are removing a single whitespace, if so remove it and the next char type + // else we just remove the whitespace + bool only_whitespace = false; + if (_is_whitespace(text[line][column]) && _is_whitespace(text[line][column + 1])) { + only_whitespace = true; + } else if (_is_whitespace(text[line][column])) { + // remove the single whitespace + column++; } - while (column < text[line].length()) { + // check if its a text char + bool only_char = (_is_text_char(text[line][column]) && !only_whitespace); - bool ischar = _is_text_char(text[line][column]); + // if its not whitespace or char then symbol. + bool only_symbols = !(only_whitespace || only_char); - if (prev_char && !ischar) + while (column < curline_len) { + bool is_whitespace = _is_whitespace(text[line][column]); + bool is_text_char = _is_text_char(text[line][column]); + + if (only_whitespace && !is_whitespace) { break; - prev_char = ischar; + } else if (only_char && !is_text_char) { + break; + } else if (only_symbols && (is_whitespace || is_text_char)) { + break; + } column++; } next_line = line; next_column = column; + } else { next_column = cursor.column < curline_len ? (cursor.column + 1) : 0; } |