mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Code style improvements to text_edit and related
This commit is contained in:
parent
61630d4e1e
commit
f587a21899
6 changed files with 107 additions and 126 deletions
|
@ -196,7 +196,8 @@ void FindReplaceBar::_replace() {
|
|||
int search_text_len = get_search_text().length();
|
||||
|
||||
text_editor->begin_complex_operation();
|
||||
if (selection_enabled && is_selection_only()) { // To restrict search_current() to selected region
|
||||
if (selection_enabled && is_selection_only()) {
|
||||
// Restrict search_current() to selected region.
|
||||
text_editor->set_caret_line(selection_begin.width, false, true, 0, 0);
|
||||
text_editor->set_caret_column(selection_begin.height, true, 0);
|
||||
}
|
||||
|
@ -210,7 +211,8 @@ void FindReplaceBar::_replace() {
|
|||
Point2i match_to(result_line, result_col + search_text_len);
|
||||
if (!(match_from < selection_begin || match_to > selection_end)) {
|
||||
text_editor->insert_text_at_caret(repl_text, 0);
|
||||
if (match_to.x == selection_end.x) { // Adjust selection bounds if necessary
|
||||
if (match_to.x == selection_end.x) {
|
||||
// Adjust selection bounds if necessary.
|
||||
selection_end.y += repl_text.length() - search_text_len;
|
||||
}
|
||||
}
|
||||
|
@ -224,7 +226,7 @@ void FindReplaceBar::_replace() {
|
|||
needs_to_count_results = true;
|
||||
|
||||
if (selection_enabled && is_selection_only()) {
|
||||
// Reselect in order to keep 'Replace' restricted to selection
|
||||
// Reselect in order to keep 'Replace' restricted to selection.
|
||||
text_editor->select(selection_begin.x, selection_begin.y, selection_end.x, selection_end.y, 0);
|
||||
} else {
|
||||
text_editor->deselect(0);
|
||||
|
@ -274,7 +276,7 @@ void FindReplaceBar::_replace_all() {
|
|||
|
||||
if (search_current()) {
|
||||
do {
|
||||
// replace area
|
||||
// Replace area.
|
||||
Point2i match_from(result_line, result_col);
|
||||
Point2i match_to(result_line, result_col + search_text_len);
|
||||
|
||||
|
@ -698,7 +700,7 @@ FindReplaceBar::FindReplaceBar() {
|
|||
hbc_option_replace = memnew(HBoxContainer);
|
||||
vbc_option->add_child(hbc_option_replace);
|
||||
|
||||
// search toolbar
|
||||
// Search toolbar
|
||||
search_text = memnew(LineEdit);
|
||||
vbc_lineedit->add_child(search_text);
|
||||
search_text->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
|
||||
|
@ -733,7 +735,7 @@ FindReplaceBar::FindReplaceBar() {
|
|||
whole_words->set_focus_mode(FOCUS_NONE);
|
||||
whole_words->connect("toggled", callable_mp(this, &FindReplaceBar::_search_options_changed));
|
||||
|
||||
// replace toolbar
|
||||
// Replace toolbar
|
||||
replace_text = memnew(LineEdit);
|
||||
vbc_lineedit->add_child(replace_text);
|
||||
replace_text->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
|
||||
|
@ -889,7 +891,7 @@ void CodeTextEditor::_line_col_changed() {
|
|||
int positional_column = 0;
|
||||
for (int i = 0; i < text_editor->get_caret_column(); i++) {
|
||||
if (line[i] == '\t') {
|
||||
positional_column += text_editor->get_indent_size(); //tab size
|
||||
positional_column += text_editor->get_indent_size(); // Tab size
|
||||
} else {
|
||||
positional_column += 1;
|
||||
}
|
||||
|
@ -1127,8 +1129,7 @@ void CodeTextEditor::insert_final_newline() {
|
|||
|
||||
String line = text_editor->get_line(final_line);
|
||||
|
||||
//length 0 means it's already an empty line,
|
||||
//no need to add a newline
|
||||
// Length 0 means it's already an empty line, no need to add a newline.
|
||||
if (line.length() > 0 && !line.ends_with("\n")) {
|
||||
text_editor->begin_complex_operation();
|
||||
|
||||
|
@ -1305,11 +1306,11 @@ void CodeTextEditor::move_lines_up() {
|
|||
|
||||
Vector<int> caret_edit_order = text_editor->get_caret_index_edit_order();
|
||||
|
||||
// Lists of carets representing each group
|
||||
// Lists of carets representing each group.
|
||||
Vector<Vector<int>> caret_groups;
|
||||
Vector<Pair<int, int>> group_borders;
|
||||
|
||||
// Search for groups of carets and their selections residing on the same lines
|
||||
// Search for groups of carets and their selections residing on the same lines.
|
||||
for (int i = 0; i < caret_edit_order.size(); i++) {
|
||||
int c = caret_edit_order[i];
|
||||
|
||||
|
@ -1333,7 +1334,7 @@ void CodeTextEditor::move_lines_up() {
|
|||
}
|
||||
group_border.first = next_start_pos;
|
||||
new_group.push_back(c_next);
|
||||
// If the last caret is added to the current group there is no need to process it again
|
||||
// If the last caret is added to the current group there is no need to process it again.
|
||||
if (j + 1 == caret_edit_order.size() - 1) {
|
||||
i++;
|
||||
}
|
||||
|
@ -1347,12 +1348,12 @@ void CodeTextEditor::move_lines_up() {
|
|||
continue;
|
||||
}
|
||||
|
||||
// If the group starts overlapping with the upper group don't move it
|
||||
// If the group starts overlapping with the upper group don't move it.
|
||||
if (i < group_borders.size() - 1 && group_borders[i].first - 1 <= group_borders[i + 1].second) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// We have to remember caret positions and selections prior to line swapping
|
||||
// We have to remember caret positions and selections prior to line swapping.
|
||||
Vector<Vector<int>> caret_group_parameters;
|
||||
|
||||
for (int j = 0; j < caret_groups[i].size(); j++) {
|
||||
|
@ -1400,11 +1401,11 @@ void CodeTextEditor::move_lines_down() {
|
|||
|
||||
Vector<int> caret_edit_order = text_editor->get_caret_index_edit_order();
|
||||
|
||||
// Lists of carets representing each group
|
||||
// Lists of carets representing each group.
|
||||
Vector<Vector<int>> caret_groups;
|
||||
Vector<Pair<int, int>> group_borders;
|
||||
Vector<int> group_border_ends;
|
||||
// Search for groups of carets and their selections residing on the same lines
|
||||
// Search for groups of carets and their selections residing on the same lines.
|
||||
for (int i = 0; i < caret_edit_order.size(); i++) {
|
||||
int c = caret_edit_order[i];
|
||||
|
||||
|
@ -1426,7 +1427,7 @@ void CodeTextEditor::move_lines_down() {
|
|||
if (next_end_pos == current_start_pos || next_end_pos + 1 == current_start_pos) {
|
||||
group_border.first = next_start_pos;
|
||||
new_group.push_back(c_next);
|
||||
// If the last caret is added to the current group there is no need to process it again
|
||||
// If the last caret is added to the current group there is no need to process it again.
|
||||
if (j + 1 == caret_edit_order.size() - 1) {
|
||||
i++;
|
||||
}
|
||||
|
@ -1444,12 +1445,12 @@ void CodeTextEditor::move_lines_down() {
|
|||
continue;
|
||||
}
|
||||
|
||||
// If the group starts overlapping with the upper group don't move it
|
||||
// If the group starts overlapping with the upper group don't move it.
|
||||
if (i > 0 && group_border_ends[i] + 1 >= group_borders[i - 1].first) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// We have to remember caret positions and selections prior to line swapping
|
||||
// We have to remember caret positions and selections prior to line swapping.
|
||||
Vector<Vector<int>> caret_group_parameters;
|
||||
|
||||
for (int j = 0; j < caret_groups[i].size(); j++) {
|
||||
|
@ -1457,15 +1458,15 @@ void CodeTextEditor::move_lines_down() {
|
|||
int cursor_line = text_editor->get_caret_line(c);
|
||||
int cursor_column = text_editor->get_caret_column(c);
|
||||
|
||||
if (text_editor->has_selection(c)) {
|
||||
int from_line = text_editor->get_selection_from_line(c);
|
||||
int from_col = text_editor->get_selection_from_column(c);
|
||||
int to_line = text_editor->get_selection_to_line(c);
|
||||
int to_column = text_editor->get_selection_to_column(c);
|
||||
caret_group_parameters.push_back(Vector<int>{ from_line, from_col, to_line, to_column, cursor_line, cursor_column });
|
||||
} else {
|
||||
if (!text_editor->has_selection(c)) {
|
||||
caret_group_parameters.push_back(Vector<int>{ -1, -1, -1, -1, cursor_line, cursor_column });
|
||||
continue;
|
||||
}
|
||||
int from_line = text_editor->get_selection_from_line(c);
|
||||
int from_col = text_editor->get_selection_from_column(c);
|
||||
int to_line = text_editor->get_selection_to_line(c);
|
||||
int to_column = text_editor->get_selection_to_column(c);
|
||||
caret_group_parameters.push_back(Vector<int>{ from_line, from_col, to_line, to_column, cursor_line, cursor_column });
|
||||
}
|
||||
|
||||
for (int line_id = group_borders[i].second; line_id >= group_borders[i].first; line_id--) {
|
||||
|
@ -1899,7 +1900,7 @@ int CodeTextEditor::_get_affected_lines_to(int p_caret) {
|
|||
return text_editor->get_caret_line(p_caret);
|
||||
}
|
||||
int line = text_editor->get_selection_to_line(p_caret);
|
||||
// Don't affect a line with no selected characters
|
||||
// Don't affect a line with no selected characters.
|
||||
if (text_editor->get_selection_to_column(p_caret) == 0) {
|
||||
line--;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue