Merge pull request #4062 from neikeq/pr-issue-4060

LineEdit/TextEdit: Add Shift+Delete shortcut for cut
This commit is contained in:
Rémi Verschelde 2016-03-15 14:32:40 +01:00
commit 648af0c42b
2 changed files with 65 additions and 88 deletions

View File

@ -274,6 +274,11 @@ void LineEdit::_input_event(InputEvent p_event) {
} break; } break;
case KEY_DELETE: { case KEY_DELETE: {
if (k.mod.shift && !k.mod.command && !k.mod.alt && editable) {
cut_text();
break;
}
if (editable) { if (editable) {
undo_text = text; undo_text = text;
if (selection.enabled) if (selection.enabled)

View File

@ -1957,6 +1957,12 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
if (readonly) if (readonly)
break; break;
if (k.mod.shift && !k.mod.command && !k.mod.alt) {
cut();
break;
}
int curline_len = text[cursor.line].length(); int curline_len = text[cursor.line].length();
if (cursor.line==text.size()-1 && cursor.column==curline_len) if (cursor.line==text.size()-1 && cursor.column==curline_len)
@ -2169,35 +2175,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
break; break;
} }
if (!selection.active){ cut();
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;
}
} break; } break;
case KEY_C: { case KEY_C: {
@ -2207,16 +2185,8 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
break; break;
} }
if (!selection.active){ copy();
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;
}
} break; } break;
case KEY_Z: { case KEY_Z: {
@ -2237,25 +2207,8 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
break; break;
} }
String clipboard = OS::get_singleton()->get_clipboard(); paste();
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);
}
else if (cut_copy_line)
{
cursor_set_column(0);
String ins="\n";
clipboard += ins;
}
_insert_text_at_cursor(clipboard);
update();
} break; } break;
case KEY_SPACE: { case KEY_SPACE: {
#ifdef OSX_ENABLED #ifdef OSX_ENABLED
@ -3028,8 +2981,20 @@ void TextEdit::set_auto_indent(bool p_auto_indent) {
void TextEdit::cut() { void TextEdit::cut() {
if (!selection.active) if (!selection.active) {
return;
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); String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
OS::get_singleton()->set_clipboard(clipboard); OS::get_singleton()->set_clipboard(clipboard);
@ -3041,7 +3006,8 @@ void TextEdit::cut() {
selection.active=false; selection.active=false;
selection.selecting_mode=Selection::MODE_NONE; selection.selecting_mode=Selection::MODE_NONE;
update(); update();
cut_copy_line = false;
}
} }
void TextEdit::copy() { void TextEdit::copy() {
@ -3049,32 +3015,38 @@ void TextEdit::copy() {
if (!selection.active) if (!selection.active)
return; return;
print_line("from line: "+itos(selection.from_line)); if (!selection.active) {
print_line("from column: "+itos(selection.from_column)); String clipboard = _base_get_text(cursor.line,0,cursor.line,text[cursor.line].length());
print_line("to line: "+itos(selection.to_line)); OS::get_singleton()->set_clipboard(clipboard);
print_line("to column: "+itos(selection.to_column)); cut_copy_line = true;
} else {
String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,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); OS::get_singleton()->set_clipboard(clipboard);
cut_copy_line = false;
}
} }
void TextEdit::paste() { void TextEdit::paste() {
String clipboard = OS::get_singleton()->get_clipboard();
if (selection.active) { 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_line(selection.from_line);
cursor_set_column(selection.from_column); cursor_set_column(selection.from_column);
_remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); } else if (cut_copy_line) {
selection.active=false;
selection.selecting_mode=Selection::MODE_NONE;
cursor_set_column(0);
String ins="\n";
clipboard += ins;
} }
String clipboard = OS::get_singleton()->get_clipboard();
_insert_text_at_cursor(clipboard); _insert_text_at_cursor(clipboard);
update(); update();
} }
void TextEdit::select_all() { void TextEdit::select_all() {