summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulb23 <p_batty@hotmail.co.uk>2016-05-19 15:32:41 +0100
committerPaulb23 <p_batty@hotmail.co.uk>2016-05-19 15:32:41 +0100
commit2eb4e7c103793c7ca915b5f1cfc1a8bf356c0152 (patch)
tree943e820b7af01535cef65504ef4da26b57f69ea0
parent02f3e7e766ef33de51f0d2dffdb5b1abf4b44022 (diff)
Multiline duplication, issue #4661
-rw-r--r--tools/editor/plugins/script_editor_plugin.cpp31
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;