You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Style: Enforce braces around if blocks and loops
Using clang-tidy's `readability-braces-around-statements`. https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
This commit is contained in:
@@ -54,8 +54,9 @@ int GotoLineDialog::get_line() const {
|
||||
}
|
||||
|
||||
void GotoLineDialog::ok_pressed() {
|
||||
if (get_line() < 1 || get_line() > text_editor->get_line_count())
|
||||
if (get_line() < 1 || get_line() > text_editor->get_line_count()) {
|
||||
return;
|
||||
}
|
||||
text_editor->unfold_line(get_line() - 1);
|
||||
text_editor->cursor_set_line(get_line() - 1);
|
||||
hide();
|
||||
@@ -285,14 +286,16 @@ void FindReplaceBar::_get_search_from(int &r_line, int &r_col) {
|
||||
}
|
||||
|
||||
void FindReplaceBar::_update_results_count() {
|
||||
if (results_count != -1)
|
||||
if (results_count != -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
results_count = 0;
|
||||
|
||||
String searched = get_search_text();
|
||||
if (searched.empty())
|
||||
if (searched.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String full_text = text_edit->get_text();
|
||||
|
||||
@@ -300,15 +303,18 @@ void FindReplaceBar::_update_results_count() {
|
||||
|
||||
while (true) {
|
||||
int pos = is_case_sensitive() ? full_text.find(searched, from_pos) : full_text.findn(searched, from_pos);
|
||||
if (pos == -1)
|
||||
if (pos == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_whole_words()) {
|
||||
from_pos++; // Making sure we won't hit the same match next time, if we get out via a continue.
|
||||
if (pos > 0 && !is_symbol(full_text[pos - 1]))
|
||||
if (pos > 0 && !is_symbol(full_text[pos - 1])) {
|
||||
continue;
|
||||
if (pos + searched.length() < full_text.length() && !is_symbol(full_text[pos + searched.length()]))
|
||||
}
|
||||
if (pos + searched.length() < full_text.length() && !is_symbol(full_text[pos + searched.length()])) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
results_count++;
|
||||
@@ -330,10 +336,12 @@ void FindReplaceBar::_update_matches_label() {
|
||||
bool FindReplaceBar::search_current() {
|
||||
uint32_t flags = 0;
|
||||
|
||||
if (is_whole_words())
|
||||
if (is_whole_words()) {
|
||||
flags |= TextEdit::SEARCH_WHOLE_WORDS;
|
||||
if (is_case_sensitive())
|
||||
}
|
||||
if (is_case_sensitive()) {
|
||||
flags |= TextEdit::SEARCH_MATCH_CASE;
|
||||
}
|
||||
|
||||
int line, col;
|
||||
_get_search_from(line, col);
|
||||
@@ -342,29 +350,34 @@ bool FindReplaceBar::search_current() {
|
||||
}
|
||||
|
||||
bool FindReplaceBar::search_prev() {
|
||||
if (!is_visible())
|
||||
if (!is_visible()) {
|
||||
popup_search(true);
|
||||
}
|
||||
|
||||
uint32_t flags = 0;
|
||||
String text = get_search_text();
|
||||
|
||||
if (is_whole_words())
|
||||
if (is_whole_words()) {
|
||||
flags |= TextEdit::SEARCH_WHOLE_WORDS;
|
||||
if (is_case_sensitive())
|
||||
}
|
||||
if (is_case_sensitive()) {
|
||||
flags |= TextEdit::SEARCH_MATCH_CASE;
|
||||
}
|
||||
|
||||
flags |= TextEdit::SEARCH_BACKWARDS;
|
||||
|
||||
int line, col;
|
||||
_get_search_from(line, col);
|
||||
if (text_edit->is_selection_active())
|
||||
if (text_edit->is_selection_active()) {
|
||||
col--; // Skip currently selected word.
|
||||
}
|
||||
|
||||
col -= text.length();
|
||||
if (col < 0) {
|
||||
line -= 1;
|
||||
if (line < 0)
|
||||
if (line < 0) {
|
||||
line = text_edit->get_line_count() - 1;
|
||||
}
|
||||
col = text_edit->get_line(line).length();
|
||||
}
|
||||
|
||||
@@ -372,20 +385,24 @@ bool FindReplaceBar::search_prev() {
|
||||
}
|
||||
|
||||
bool FindReplaceBar::search_next() {
|
||||
if (!is_visible())
|
||||
if (!is_visible()) {
|
||||
popup_search(true);
|
||||
}
|
||||
|
||||
uint32_t flags = 0;
|
||||
String text;
|
||||
if (replace_all_mode)
|
||||
if (replace_all_mode) {
|
||||
text = get_replace_text();
|
||||
else
|
||||
} else {
|
||||
text = get_search_text();
|
||||
}
|
||||
|
||||
if (is_whole_words())
|
||||
if (is_whole_words()) {
|
||||
flags |= TextEdit::SEARCH_WHOLE_WORDS;
|
||||
if (is_case_sensitive())
|
||||
}
|
||||
if (is_case_sensitive()) {
|
||||
flags |= TextEdit::SEARCH_MATCH_CASE;
|
||||
}
|
||||
|
||||
int line, col;
|
||||
_get_search_from(line, col);
|
||||
@@ -394,8 +411,9 @@ bool FindReplaceBar::search_next() {
|
||||
col += text.length();
|
||||
if (col > text_edit->get_line(line).length()) {
|
||||
line += 1;
|
||||
if (line >= text_edit->get_line_count())
|
||||
if (line >= text_edit->get_line_count()) {
|
||||
line = 0;
|
||||
}
|
||||
col = 0;
|
||||
}
|
||||
}
|
||||
@@ -404,8 +422,9 @@ bool FindReplaceBar::search_next() {
|
||||
}
|
||||
|
||||
void FindReplaceBar::_hide_bar() {
|
||||
if (replace_text->has_focus() || search_text->has_focus())
|
||||
if (replace_text->has_focus() || search_text->has_focus()) {
|
||||
text_edit->grab_focus();
|
||||
}
|
||||
|
||||
text_edit->set_search_text("");
|
||||
result_line = -1;
|
||||
@@ -415,8 +434,9 @@ void FindReplaceBar::_hide_bar() {
|
||||
|
||||
void FindReplaceBar::_show_search(bool p_focus_replace, bool p_show_only) {
|
||||
show();
|
||||
if (p_show_only)
|
||||
if (p_show_only) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_focus_replace) {
|
||||
search_text->deselect();
|
||||
@@ -637,8 +657,9 @@ FindReplaceBar::FindReplaceBar() {
|
||||
// be handled too late if they weren't handled here.
|
||||
void CodeTextEditor::_input(const Ref<InputEvent> &event) {
|
||||
const Ref<InputEventKey> key_event = event;
|
||||
if (!key_event.is_valid() || !key_event->is_pressed())
|
||||
if (!key_event.is_valid() || !key_event->is_pressed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ED_IS_SHORTCUT("script_text_editor/move_up", key_event)) {
|
||||
move_lines_up();
|
||||
@@ -719,8 +740,9 @@ void CodeTextEditor::_zoom_out() {
|
||||
}
|
||||
|
||||
void CodeTextEditor::_zoom_changed() {
|
||||
if (font_resize_timer->get_time_left() == 0)
|
||||
if (font_resize_timer->get_time_left() == 0) {
|
||||
font_resize_timer->start();
|
||||
}
|
||||
}
|
||||
|
||||
void CodeTextEditor::_reset_zoom() {
|
||||
@@ -763,8 +785,9 @@ void CodeTextEditor::_text_changed() {
|
||||
}
|
||||
|
||||
void CodeTextEditor::_code_complete_timer_timeout() {
|
||||
if (!is_visible_in_tree())
|
||||
if (!is_visible_in_tree()) {
|
||||
return;
|
||||
}
|
||||
text_editor->query_code_comple();
|
||||
}
|
||||
|
||||
@@ -776,8 +799,9 @@ void CodeTextEditor::_complete_request() {
|
||||
if (code_complete_func) {
|
||||
code_complete_func(code_complete_ud, ctext, &entries, forced);
|
||||
}
|
||||
if (entries.size() == 0)
|
||||
if (entries.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (List<ScriptCodeCompletionOption>::Element *E = entries.front(); E; E = E->next()) {
|
||||
E->get().icon = _get_completion_icon(E->get());
|
||||
@@ -1035,10 +1059,12 @@ void CodeTextEditor::convert_case(CaseStyle p_case) {
|
||||
|
||||
for (int i = begin; i <= end; i++) {
|
||||
int len = text_editor->get_line(i).length();
|
||||
if (i == end)
|
||||
if (i == end) {
|
||||
len = end_col;
|
||||
if (i == begin)
|
||||
}
|
||||
if (i == begin) {
|
||||
len -= begin_col;
|
||||
}
|
||||
String new_line = text_editor->get_line(i).substr(i == begin ? begin_col : 0, len);
|
||||
|
||||
switch (p_case) {
|
||||
@@ -1076,8 +1102,9 @@ void CodeTextEditor::move_lines_up() {
|
||||
int line_id = i;
|
||||
int next_id = i - 1;
|
||||
|
||||
if (line_id == 0 || next_id < 0)
|
||||
if (line_id == 0 || next_id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
text_editor->unfold_line(line_id);
|
||||
text_editor->unfold_line(next_id);
|
||||
@@ -1092,8 +1119,9 @@ void CodeTextEditor::move_lines_up() {
|
||||
int line_id = text_editor->cursor_get_line();
|
||||
int next_id = line_id - 1;
|
||||
|
||||
if (line_id == 0 || next_id < 0)
|
||||
if (line_id == 0 || next_id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
text_editor->unfold_line(line_id);
|
||||
text_editor->unfold_line(next_id);
|
||||
@@ -1117,8 +1145,9 @@ void CodeTextEditor::move_lines_down() {
|
||||
int line_id = i;
|
||||
int next_id = i + 1;
|
||||
|
||||
if (line_id == text_editor->get_line_count() - 1 || next_id > text_editor->get_line_count())
|
||||
if (line_id == text_editor->get_line_count() - 1 || next_id > text_editor->get_line_count()) {
|
||||
return;
|
||||
}
|
||||
|
||||
text_editor->unfold_line(line_id);
|
||||
text_editor->unfold_line(next_id);
|
||||
@@ -1133,8 +1162,9 @@ void CodeTextEditor::move_lines_down() {
|
||||
int line_id = text_editor->cursor_get_line();
|
||||
int next_id = line_id + 1;
|
||||
|
||||
if (line_id == text_editor->get_line_count() - 1 || next_id > text_editor->get_line_count())
|
||||
if (line_id == text_editor->get_line_count() - 1 || next_id > text_editor->get_line_count()) {
|
||||
return;
|
||||
}
|
||||
|
||||
text_editor->unfold_line(line_id);
|
||||
text_editor->unfold_line(next_id);
|
||||
@@ -1228,8 +1258,9 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) {
|
||||
int end = text_editor->get_selection_to_line();
|
||||
|
||||
// End of selection ends on the first column of the last line, ignore it.
|
||||
if (text_editor->get_selection_to_column() == 0)
|
||||
if (text_editor->get_selection_to_column() == 0) {
|
||||
end -= 1;
|
||||
}
|
||||
|
||||
int col_to = text_editor->get_selection_to_column();
|
||||
int cursor_pos = text_editor->cursor_get_column();
|
||||
@@ -1261,14 +1292,17 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) {
|
||||
int offset = (is_commented ? -1 : 1) * delimiter.length();
|
||||
int col_from = text_editor->get_selection_from_column() > 0 ? text_editor->get_selection_from_column() + offset : 0;
|
||||
|
||||
if (is_commented && text_editor->cursor_get_column() == text_editor->get_line(text_editor->cursor_get_line()).length() + 1)
|
||||
if (is_commented && text_editor->cursor_get_column() == text_editor->get_line(text_editor->cursor_get_line()).length() + 1) {
|
||||
cursor_pos += 1;
|
||||
}
|
||||
|
||||
if (text_editor->get_selection_to_column() != 0 && col_to != text_editor->get_line(text_editor->get_selection_to_line()).length() + 1)
|
||||
if (text_editor->get_selection_to_column() != 0 && col_to != text_editor->get_line(text_editor->get_selection_to_line()).length() + 1) {
|
||||
col_to += offset;
|
||||
}
|
||||
|
||||
if (text_editor->cursor_get_column() != 0)
|
||||
if (text_editor->cursor_get_column() != 0) {
|
||||
cursor_pos += offset;
|
||||
}
|
||||
|
||||
text_editor->select(begin, col_from, text_editor->get_selection_to_line(), col_to);
|
||||
text_editor->cursor_set_column(cursor_pos);
|
||||
@@ -1419,8 +1453,9 @@ void CodeTextEditor::_update_font() {
|
||||
int count = status_bar->get_child_count();
|
||||
for (int i = 0; i < count; i++) {
|
||||
Control *n = Object::cast_to<Control>(status_bar->get_child(i));
|
||||
if (n)
|
||||
if (n) {
|
||||
n->add_theme_font_override("font", status_bar_font);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1511,8 +1546,9 @@ void CodeTextEditor::set_warning_nb(int p_warning_nb) {
|
||||
warning_count_label->set_text(itos(p_warning_nb));
|
||||
warning_count_label->set_visible(p_warning_nb > 0);
|
||||
warning_button->set_visible(p_warning_nb > 0);
|
||||
if (!p_warning_nb)
|
||||
if (!p_warning_nb) {
|
||||
_set_show_warnings_panel(false);
|
||||
}
|
||||
}
|
||||
|
||||
void CodeTextEditor::toggle_bookmark() {
|
||||
|
||||
Reference in New Issue
Block a user