diff options
author | Juan Linietsky <reduzio@gmail.com> | 2015-11-18 18:42:37 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2015-11-18 18:42:37 -0300 |
commit | f2b43e3ec0723d4751c187b4716e2242e1b60e5f (patch) | |
tree | c2dde2bc52bffb1e5b7d79f80035f38db25d80f9 /scene/gui/text_edit.cpp | |
parent | 0f615c523c296cd897d77503d3f2000409690506 (diff) | |
parent | 222d112f496a5193b837854a72e4025a45a28ef2 (diff) |
Merge pull request #2769 from TheHX/text_edit_improvements
Implement Ctrl + backspace/delete to delete words
Diffstat (limited to 'scene/gui/text_edit.cpp')
-rw-r--r-- | scene/gui/text_edit.cpp | 113 |
1 files changed, 109 insertions, 4 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index be6c0d0a8b..d081e84df4 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1647,8 +1647,60 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { case KEY_BACKSPACE: { if (readonly) break; - backspace_at_cursor(); - + +#ifdef APPLE_STYLE_KEYS + if (k.mod.alt) { +#else + if (k.mod.alt) { + scancode_handled=false; + break; + } else if (k.mod.command) { +#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; + } + + column--; + } + + if (only_whitespace) { + line--; + column=text[line].length(); + } + } + + while (column>0) { + bool ischar=_is_text_char(text[line][column-1]); + + if (prev_char && !ischar) + break; + + prev_char=ischar; + column--; + + } + + _remove_text(line, column, cursor.line, cursor.column); + + cursor_set_line(line); + cursor_set_column(column); + + } else { + backspace_at_cursor(); + } + } break; case KEY_LEFT: { @@ -1789,10 +1841,63 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { if (cursor.line==text.size()-1 && cursor.column==curline_len) break; //nothing to do - int next_line = cursor.column<curline_len?cursor.line:cursor.line+1; - int next_column = cursor.column<curline_len?(cursor.column+1):0; + int next_line=cursor.column<curline_len?cursor.line:cursor.line+1; + int next_column; + +#ifdef APPLE_STYLE_KEYS + if (k.mod.alt) { +#else + if (k.mod.alt) { + scancode_handled=false; + break; + } else if (k.mod.command) { +#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; + } + } + + while (column<text[line].length()) { + + bool ischar=_is_text_char(text[line][column]); + + if (prev_char && !ischar) + break; + prev_char=ischar; + column++; + } + + next_line=line; + next_column=column; + } else { + next_column=cursor.column<curline_len?(cursor.column+1):0; + } + _remove_text(cursor.line,cursor.column,next_line,next_column); update(); + } break; #ifdef APPLE_STYLE_KEYS case KEY_HOME: { |