summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-12-09 22:15:18 +0100
committerGitHub <noreply@github.com>2019-12-09 22:15:18 +0100
commit269145a346bddae5cbbf00fd17b6c8eac4cd4665 (patch)
treef5fb980ec2067fbcbcb1156e7b02da611196ef71
parent7380fbbaeebb34168aa6998c490ef05b63125ade (diff)
parent6eaec3d10d472ca08e8f7188d22860781517950c (diff)
Merge pull request #34217 from timothyqiu/delete-lines
Fixes Delete Line doesn't delete first line in script
-rw-r--r--editor/code_editor.cpp30
-rw-r--r--editor/code_editor.h2
2 files changed, 19 insertions, 13 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index e3138dc1e5..db44edcfcb 100644
--- a/editor/code_editor.cpp
+++ b/editor/code_editor.cpp
@@ -1182,6 +1182,19 @@ void CodeTextEditor::move_lines_down() {
text_editor->update();
}
+void CodeTextEditor::_delete_line(int p_line) {
+ // this is currently intended to be called within delete_lines()
+ // so `begin_complex_operation` is ommitted here
+ text_editor->set_line(p_line, "");
+ if (p_line == 0 && text_editor->get_line_count() > 1) {
+ text_editor->cursor_set_line(1);
+ text_editor->cursor_set_column(0);
+ }
+ text_editor->backspace_at_cursor();
+ text_editor->unfold_line(p_line);
+ text_editor->cursor_set_line(p_line);
+}
+
void CodeTextEditor::delete_lines() {
text_editor->begin_complex_operation();
if (text_editor->is_selection_active()) {
@@ -1189,22 +1202,13 @@ void CodeTextEditor::delete_lines() {
int from_line = text_editor->get_selection_from_line();
int count = Math::abs(to_line - from_line) + 1;
- text_editor->cursor_set_line(to_line, false);
- while (count) {
- text_editor->set_line(text_editor->cursor_get_line(), "");
- text_editor->backspace_at_cursor();
- count--;
- if (count)
- text_editor->unfold_line(from_line);
+ text_editor->cursor_set_line(from_line, false);
+ for (int i = 0; i < count; i++) {
+ _delete_line(from_line);
}
- text_editor->cursor_set_line(from_line - 1);
text_editor->deselect();
} else {
- int line = text_editor->cursor_get_line();
- text_editor->set_line(text_editor->cursor_get_line(), "");
- text_editor->backspace_at_cursor();
- text_editor->unfold_line(line);
- text_editor->cursor_set_line(line);
+ _delete_line(text_editor->cursor_get_line());
}
text_editor->end_complex_operation();
}
diff --git a/editor/code_editor.h b/editor/code_editor.h
index f2a55cfb70..a4cd521afa 100644
--- a/editor/code_editor.h
+++ b/editor/code_editor.h
@@ -185,6 +185,8 @@ class CodeTextEditor : public VBoxContainer {
void _set_show_warnings_panel(bool p_show);
void _error_pressed(const Ref<InputEvent> &p_event);
+ void _delete_line(int p_line);
+
protected:
virtual void _load_theme_settings() {}
virtual void _validate_script() {}