Merge pull request #69617 from MewPurPur/this-darn-pixel

Fix fringe issues with shortcuts not behaving as expected for multi-carets
This commit is contained in:
Rémi Verschelde 2022-12-08 09:52:13 +01:00
commit 204715ae95
No known key found for this signature in database
GPG key ID: C3336907360768E1
3 changed files with 44 additions and 61 deletions

View file

@ -769,7 +769,7 @@ void FindInFilesPanel::draw_result_text(Object *item_obj, Rect2 rect) {
Rect2 match_rect = rect; Rect2 match_rect = rect;
match_rect.position.x += font->get_string_size(item_text.left(r.begin_trimmed), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x - 1; match_rect.position.x += font->get_string_size(item_text.left(r.begin_trimmed), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x - 1;
match_rect.size.x = font->get_string_size(_search_text_label->get_text(), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x + 2; match_rect.size.x = font->get_string_size(_search_text_label->get_text(), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x + 1;
match_rect.position.y += 1 * EDSCALE; match_rect.position.y += 1 * EDSCALE;
match_rect.size.y -= 2 * EDSCALE; match_rect.size.y -= 2 * EDSCALE;

View file

@ -1223,7 +1223,9 @@ void ScriptTextEditor::_edit_option(int p_op) {
code_editor->duplicate_selection(); code_editor->duplicate_selection();
} break; } break;
case EDIT_TOGGLE_FOLD_LINE: { case EDIT_TOGGLE_FOLD_LINE: {
tx->toggle_foldable_line(tx->get_caret_line()); for (int caret_idx = 0; caret_idx < tx->get_caret_count(); caret_idx++) {
tx->toggle_foldable_line(tx->get_caret_line(caret_idx));
}
tx->queue_redraw(); tx->queue_redraw();
} break; } break;
case EDIT_FOLD_ALL_LINES: { case EDIT_FOLD_ALL_LINES: {
@ -1291,13 +1293,14 @@ void ScriptTextEditor::_edit_option(int p_op) {
} break; } break;
case EDIT_EVALUATE: { case EDIT_EVALUATE: {
Expression expression; Expression expression;
Vector<String> lines = code_editor->get_text_editor()->get_selected_text().split("\n"); tx->begin_complex_operation();
for (int caret_idx = 0; caret_idx < tx->get_caret_count(); caret_idx++) {
Vector<String> lines = tx->get_selected_text(caret_idx).split("\n");
PackedStringArray results; PackedStringArray results;
for (int i = 0; i < lines.size(); i++) { for (int i = 0; i < lines.size(); i++) {
String line = lines[i]; String line = lines[i];
String whitespace = line.substr(0, line.size() - line.strip_edges(true, false).size()); //extract the whitespace at the beginning String whitespace = line.substr(0, line.size() - line.strip_edges(true, false).size()); // Extract the whitespace at the beginning.
if (expression.parse(line) == OK) { if (expression.parse(line) == OK) {
Variant result = expression.execute(Array(), Variant(), false, true); Variant result = expression.execute(Array(), Variant(), false, true);
if (expression.get_error_text().is_empty()) { if (expression.get_error_text().is_empty()) {
@ -1309,10 +1312,9 @@ void ScriptTextEditor::_edit_option(int p_op) {
results.push_back(line); results.push_back(line);
} }
} }
tx->insert_text_at_caret(String("\n").join(results), caret_idx);
code_editor->get_text_editor()->begin_complex_operation(); //prevents creating a two-step undo }
code_editor->get_text_editor()->insert_text_at_caret(String("\n").join(results)); tx->end_complex_operation();
code_editor->get_text_editor()->end_complex_operation();
} break; } break;
case SEARCH_FIND: { case SEARCH_FIND: {
code_editor->get_find_replace_bar()->popup_search(); code_editor->get_find_replace_bar()->popup_search();
@ -1327,14 +1329,14 @@ void ScriptTextEditor::_edit_option(int p_op) {
code_editor->get_find_replace_bar()->popup_replace(); code_editor->get_find_replace_bar()->popup_replace();
} break; } break;
case SEARCH_IN_FILES: { case SEARCH_IN_FILES: {
String selected_text = code_editor->get_text_editor()->get_selected_text(); String selected_text = tx->get_selected_text();
// Yep, because it doesn't make sense to instance this dialog for every single script open... // Yep, because it doesn't make sense to instance this dialog for every single script open...
// So this will be delegated to the ScriptEditor. // So this will be delegated to the ScriptEditor.
emit_signal(SNAME("search_in_files_requested"), selected_text); emit_signal(SNAME("search_in_files_requested"), selected_text);
} break; } break;
case REPLACE_IN_FILES: { case REPLACE_IN_FILES: {
String selected_text = code_editor->get_text_editor()->get_selected_text(); String selected_text = tx->get_selected_text();
emit_signal(SNAME("replace_in_files_requested"), selected_text); emit_signal(SNAME("replace_in_files_requested"), selected_text);
} break; } break;
@ -1358,10 +1360,12 @@ void ScriptTextEditor::_edit_option(int p_op) {
code_editor->remove_all_bookmarks(); code_editor->remove_all_bookmarks();
} break; } break;
case DEBUG_TOGGLE_BREAKPOINT: { case DEBUG_TOGGLE_BREAKPOINT: {
int line = tx->get_caret_line(); 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); bool dobreak = !tx->is_line_breakpointed(line);
tx->set_line_as_breakpoint(line, dobreak); tx->set_line_as_breakpoint(line, dobreak);
EditorDebuggerNode::get_singleton()->set_breakpoint(script->get_path(), line + 1, dobreak); EditorDebuggerNode::get_singleton()->set_breakpoint(script->get_path(), line + 1, dobreak);
}
} break; } break;
case DEBUG_REMOVE_ALL_BREAKPOINTS: { case DEBUG_REMOVE_ALL_BREAKPOINTS: {
PackedInt32Array bpoints = tx->get_breakpointed_lines(); PackedInt32Array bpoints = tx->get_breakpointed_lines();
@ -1379,26 +1383,14 @@ void ScriptTextEditor::_edit_option(int p_op) {
return; return;
} }
tx->remove_secondary_carets(); int current_line = tx->get_caret_line();
int line = tx->get_caret_line(); int bpoint_idx = 0;
if (current_line < (int)bpoints[bpoints.size() - 1]) {
// wrap around while (bpoint_idx < bpoints.size() && bpoints[bpoint_idx] <= current_line) {
if (line >= (int)bpoints[bpoints.size() - 1]) { bpoint_idx++;
tx->unfold_line(bpoints[0]);
tx->set_caret_line(bpoints[0]);
tx->center_viewport_to_caret();
} else {
for (int i = 0; i < bpoints.size(); i++) {
int bline = bpoints[i];
if (bline > line) {
tx->unfold_line(bline);
tx->set_caret_line(bline);
tx->center_viewport_to_caret();
return;
} }
} }
} code_editor->goto_line_centered(bpoints[bpoint_idx]);
} break; } break;
case DEBUG_GOTO_PREV_BREAKPOINT: { case DEBUG_GOTO_PREV_BREAKPOINT: {
PackedInt32Array bpoints = tx->get_breakpointed_lines(); PackedInt32Array bpoints = tx->get_breakpointed_lines();
@ -1406,25 +1398,14 @@ void ScriptTextEditor::_edit_option(int p_op) {
return; return;
} }
tx->remove_secondary_carets(); int current_line = tx->get_caret_line();
int line = tx->get_caret_line(); int bpoint_idx = bpoints.size() - 1;
// wrap around if (current_line > (int)bpoints[0]) {
if (line <= (int)bpoints[0]) { while (bpoint_idx >= 0 && bpoints[bpoint_idx] >= current_line) {
tx->unfold_line(bpoints[bpoints.size() - 1]); bpoint_idx--;
tx->set_caret_line(bpoints[bpoints.size() - 1]);
tx->center_viewport_to_caret();
} else {
for (int i = bpoints.size() - 1; i >= 0; i--) {
int bline = bpoints[i];
if (bline < line) {
tx->unfold_line(bline);
tx->set_caret_line(bline);
tx->center_viewport_to_caret();
return;
} }
} }
} code_editor->goto_line_centered(bpoints[bpoint_idx]);
} break; } break;
case HELP_CONTEXTUAL: { case HELP_CONTEXTUAL: {
String text = tx->get_selected_text(0); String text = tx->get_selected_text(0);
@ -1835,7 +1816,7 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
base = _find_node_for_script(base, base, script); base = _find_node_for_script(base, base, script);
} }
ScriptLanguage::LookupResult result; ScriptLanguage::LookupResult result;
if (script->get_language()->lookup_code(code_editor->get_text_editor()->get_text_for_symbol_lookup(), word_at_pos, script->get_path(), base, result) == OK) { if (script->get_language()->lookup_code(tx->get_text_for_symbol_lookup(), word_at_pos, script->get_path(), base, result) == OK) {
open_docs = true; open_docs = true;
} }
} }

View file

@ -353,7 +353,9 @@ void TextEditor::_edit_option(int p_op) {
code_editor->duplicate_selection(); code_editor->duplicate_selection();
} break; } break;
case EDIT_TOGGLE_FOLD_LINE: { case EDIT_TOGGLE_FOLD_LINE: {
tx->toggle_foldable_line(tx->get_caret_line()); for (int caret_idx = 0; caret_idx < tx->get_caret_count(); caret_idx++) {
tx->toggle_foldable_line(tx->get_caret_line(caret_idx));
}
tx->queue_redraw(); tx->queue_redraw();
} break; } break;
case EDIT_FOLD_ALL_LINES: { case EDIT_FOLD_ALL_LINES: {