summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Verschelde <remi@verschelde.fr>2016-03-15 14:32:40 +0100
committerRémi Verschelde <remi@verschelde.fr>2016-03-15 14:32:40 +0100
commit648af0c42b57fd6a70ce1751311dd5ec23a3daf8 (patch)
treec1eb71871c4c179f04e13c45c7174c9ef762001b
parentc9a401e54172d87ed8c541b563b471d0ff36a33b (diff)
parentfac027cb14a730c1d8cca080dad733663c287a2d (diff)
Merge pull request #4062 from neikeq/pr-issue-4060
LineEdit/TextEdit: Add Shift+Delete shortcut for cut
-rw-r--r--scene/gui/line_edit.cpp5
-rw-r--r--scene/gui/text_edit.cpp132
2 files changed, 57 insertions, 80 deletions
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 3953ef06a5..21dee62b38 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -274,6 +274,11 @@ void LineEdit::_input_event(InputEvent p_event) {
} break;
case KEY_DELETE: {
+ if (k.mod.shift && !k.mod.command && !k.mod.alt && editable) {
+ cut_text();
+ break;
+ }
+
if (editable) {
undo_text = text;
if (selection.enabled)
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index e268375c8a..b80597560d 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -1957,6 +1957,12 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
if (readonly)
break;
+
+ if (k.mod.shift && !k.mod.command && !k.mod.alt) {
+ cut();
+ break;
+ }
+
int curline_len = text[cursor.line].length();
if (cursor.line==text.size()-1 && cursor.column==curline_len)
@@ -2169,35 +2175,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
break;
}
- if (!selection.active){
-
- String clipboard = text[cursor.line];
- OS::get_singleton()->set_clipboard(clipboard);
- cursor_set_line(cursor.line);
- cursor_set_column(0);
- _remove_text(cursor.line,0,cursor.line,text[cursor.line].length());
-
- backspace_at_cursor();
- update();
- cursor_set_line(cursor.line+1);
- cut_copy_line = true;
-
- }
- else
- {
-
- String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
- OS::get_singleton()->set_clipboard(clipboard);
-
- cursor_set_line(selection.from_line);
- cursor_set_column(selection.from_column);
-
- _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
- selection.active=false;
- selection.selecting_mode=Selection::MODE_NONE;
- update();
- cut_copy_line = false;
- }
+ cut();
} break;
case KEY_C: {
@@ -2207,16 +2185,8 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
break;
}
- if (!selection.active){
- String clipboard = _base_get_text(cursor.line,0,cursor.line,text[cursor.line].length());
- OS::get_singleton()->set_clipboard(clipboard);
- cut_copy_line = true;
- }
- else{
- String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
- OS::get_singleton()->set_clipboard(clipboard);
- cut_copy_line = false;
- }
+ copy();
+
} break;
case KEY_Z: {
@@ -2237,25 +2207,8 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
break;
}
- String clipboard = OS::get_singleton()->get_clipboard();
-
- if (selection.active) {
- selection.active=false;
- _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
- cursor_set_line(selection.from_line);
- cursor_set_column(selection.from_column);
+ paste();
- }
- else if (cut_copy_line)
- {
- cursor_set_column(0);
- String ins="\n";
- clipboard += ins;
- }
-
- _insert_text_at_cursor(clipboard);
-
- update();
} break;
case KEY_SPACE: {
#ifdef OSX_ENABLED
@@ -3028,20 +2981,33 @@ void TextEdit::set_auto_indent(bool p_auto_indent) {
void TextEdit::cut() {
- if (!selection.active)
- return;
+ if (!selection.active) {
- String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
- OS::get_singleton()->set_clipboard(clipboard);
+ String clipboard = text[cursor.line];
+ OS::get_singleton()->set_clipboard(clipboard);
+ cursor_set_line(cursor.line);
+ cursor_set_column(0);
+ _remove_text(cursor.line,0,cursor.line,text[cursor.line].length());
- cursor_set_line(selection.from_line);
- cursor_set_column(selection.from_column);
+ backspace_at_cursor();
+ update();
+ cursor_set_line(cursor.line+1);
+ cut_copy_line = true;
- _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
- selection.active=false;
- selection.selecting_mode=Selection::MODE_NONE;
- update();
+ } else {
+ String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
+ OS::get_singleton()->set_clipboard(clipboard);
+
+ cursor_set_line(selection.from_line);
+ cursor_set_column(selection.from_column);
+
+ _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
+ selection.active=false;
+ selection.selecting_mode=Selection::MODE_NONE;
+ update();
+ cut_copy_line = false;
+ }
}
void TextEdit::copy() {
@@ -3049,32 +3015,38 @@ void TextEdit::copy() {
if (!selection.active)
return;
- print_line("from line: "+itos(selection.from_line));
- print_line("from column: "+itos(selection.from_column));
- print_line("to line: "+itos(selection.to_line));
- print_line("to column: "+itos(selection.to_column));
-
- String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
- OS::get_singleton()->set_clipboard(clipboard);
-
+ if (!selection.active) {
+ String clipboard = _base_get_text(cursor.line,0,cursor.line,text[cursor.line].length());
+ OS::get_singleton()->set_clipboard(clipboard);
+ cut_copy_line = true;
+ } else {
+ String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
+ OS::get_singleton()->set_clipboard(clipboard);
+ cut_copy_line = false;
+ }
}
+
void TextEdit::paste() {
+ String clipboard = OS::get_singleton()->get_clipboard();
+
if (selection.active) {
+ selection.active=false;
+ selection.selecting_mode=Selection::MODE_NONE;
+ _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
cursor_set_line(selection.from_line);
cursor_set_column(selection.from_column);
- _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
- selection.active=false;
- selection.selecting_mode=Selection::MODE_NONE;
+ } else if (cut_copy_line) {
+ cursor_set_column(0);
+ String ins="\n";
+ clipboard += ins;
}
- String clipboard = OS::get_singleton()->get_clipboard();
_insert_text_at_cursor(clipboard);
update();
-
}
void TextEdit::select_all() {