diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2016-05-21 11:32:04 +0200 |
---|---|---|
committer | Rémi Verschelde <remi@verschelde.fr> | 2016-05-21 11:32:04 +0200 |
commit | 8061be1465638da27cd1dfcc4897f4913e36ece9 (patch) | |
tree | 671f18f722a06c85974c85f735fc771b30a20eb0 | |
parent | 674cfe21d3b4e8db0aac548c4c579a55503201a0 (diff) | |
parent | 2eb4e7c103793c7ca915b5f1cfc1a8bf356c0152 (diff) |
Merge pull request #4719 from Paulb23/multiline_duplication
Multiline duplication, issue #4661
-rw-r--r-- | tools/editor/plugins/script_editor_plugin.cpp | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp index d8d5fddfe9..9ad827e0d8 100644 --- a/tools/editor/plugins/script_editor_plugin.cpp +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -1252,16 +1252,35 @@ void ScriptEditor::_menu_option(int p_option) { Ref<Script> scr = current->get_edited_script(); if (scr.is_null()) return; - int line = tx->cursor_get_line(); - int next_line = line + 1; + + int from_line = tx->cursor_get_line(); + int to_line = tx->cursor_get_line(); int column = tx->cursor_get_column(); - if (line >= tx->get_line_count() - 1) - tx->set_line(line, tx->get_line(line) + "\n"); + if (tx->is_selection_active()) { + from_line = tx->get_selection_from_line(); + to_line = tx->get_selection_to_line(); + column = tx->cursor_get_column(); + } + int next_line = to_line + 1; + + tx->begin_complex_operation(); + for (int i = from_line; i <= to_line; i++) { + + if (i >= tx->get_line_count() - 1) { + tx->set_line(i, tx->get_line(i) + "\n"); + } + String line_clone = tx->get_line(i); + tx->insert_at(line_clone, next_line); + next_line++; + } - String line_clone = tx->get_line(line); - tx->insert_at(line_clone, next_line); tx->cursor_set_column(column); + if (tx->is_selection_active()) { + tx->select(to_line + 1, tx->get_selection_from_column(), next_line - 1, tx->get_selection_to_column()); + } + + tx->end_complex_operation(); tx->update(); } break; |