From 222d112f496a5193b837854a72e4025a45a28ef2 Mon Sep 17 00:00:00 2001 From: Franklin Sobrinho Date: Thu, 12 Nov 2015 13:35:48 -0300 Subject: [PATCH] Implement Ctrl + backspace/delete to delete words --- scene/gui/text_edit.cpp | 113 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 109 insertions(+), 4 deletions(-) diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index be6c0d0a8bd..d081e84df41 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