mirror of
https://github.com/godotengine/godot.git
synced 2025-10-20 08:23:29 +00:00
Rework code editor multiline operations
Fix bugs if 2 selections were on same line. Fix bugs when selection ended at new line. Make carets stay in place after operation and on undo. Affects: delete lines, move lines, toggle comments, bookmarks and breakpoints.
This commit is contained in:
parent
27fb53024b
commit
bdfb10fb98
3 changed files with 169 additions and 161 deletions
|
@ -1362,11 +1362,36 @@ void ScriptTextEditor::_edit_option(int p_op) {
|
|||
code_editor->remove_all_bookmarks();
|
||||
} break;
|
||||
case DEBUG_TOGGLE_BREAKPOINT: {
|
||||
for (int caret_idx = 0; caret_idx < tx->get_caret_count(); caret_idx++) {
|
||||
int line = tx->get_caret_line(caret_idx);
|
||||
bool dobreak = !tx->is_line_breakpointed(line);
|
||||
tx->set_line_as_breakpoint(line, dobreak);
|
||||
EditorDebuggerNode::get_singleton()->set_breakpoint(script->get_path(), line + 1, dobreak);
|
||||
Vector<int> caret_edit_order = tx->get_caret_index_edit_order();
|
||||
caret_edit_order.reverse();
|
||||
int last_line = -1;
|
||||
for (const int &c : caret_edit_order) {
|
||||
int from = tx->has_selection(c) ? tx->get_selection_from_line(c) : tx->get_caret_line(c);
|
||||
from += from == last_line ? 1 : 0;
|
||||
int to = tx->has_selection(c) ? tx->get_selection_to_line(c) : tx->get_caret_line(c);
|
||||
if (to < from) {
|
||||
continue;
|
||||
}
|
||||
// Check first if there's any lines with breakpoints in the selection.
|
||||
bool selection_has_breakpoints = false;
|
||||
for (int line = from; line <= to; line++) {
|
||||
if (tx->is_line_breakpointed(line)) {
|
||||
selection_has_breakpoints = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Set breakpoint on caret or remove all bookmarks from the selection.
|
||||
if (!selection_has_breakpoints) {
|
||||
if (tx->get_caret_line(c) != last_line) {
|
||||
tx->set_line_as_breakpoint(tx->get_caret_line(c), true);
|
||||
}
|
||||
} else {
|
||||
for (int line = from; line <= to; line++) {
|
||||
tx->set_line_as_breakpoint(line, false);
|
||||
}
|
||||
}
|
||||
last_line = to;
|
||||
}
|
||||
} break;
|
||||
case DEBUG_REMOVE_ALL_BREAKPOINTS: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue