Skip to content

Commit

Permalink
Merge pull request #34217 from timothyqiu/delete-lines
Browse files Browse the repository at this point in the history
Fixes Delete Line doesn't delete first line in script
  • Loading branch information
akien-mga authored Dec 9, 2019
2 parents 7380fbb + 6eaec3d commit 269145a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
30 changes: 17 additions & 13 deletions editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1182,29 +1182,33 @@ 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()) {
int to_line = text_editor->get_selection_to_line();
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();
}
Expand Down
2 changes: 2 additions & 0 deletions editor/code_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down

0 comments on commit 269145a

Please sign in to comment.