summaryrefslogtreecommitdiff
path: root/editor/code_editor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/code_editor.cpp')
-rw-r--r--editor/code_editor.cpp56
1 files changed, 48 insertions, 8 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index 7c396e1da3..89a88dc6e7 100644
--- a/editor/code_editor.cpp
+++ b/editor/code_editor.cpp
@@ -152,6 +152,7 @@ bool FindReplaceBar::_search(uint32_t p_flags, int p_from_line, int p_from_col)
text_edit->cursor_set_line(line, false);
text_edit->cursor_set_column(col + text.length(), false);
text_edit->center_viewport_to_cursor();
+ text_edit->select(line, col, line, col + text.length());
}
text_edit->set_search_text(text);
@@ -161,7 +162,8 @@ bool FindReplaceBar::_search(uint32_t p_flags, int p_from_line, int p_from_col)
result_line = line;
result_col = col;
- set_error("");
+ _update_results_count();
+ set_error(vformat(TTR("Found %d match(es)."), results_count));
} else {
result_line = -1;
result_col = -1;
@@ -184,6 +186,8 @@ void FindReplaceBar::_replace() {
text_edit->insert_text_at_cursor(get_replace_text());
text_edit->end_complex_operation();
+
+ results_count = -1;
}
search_current();
@@ -271,6 +275,7 @@ void FindReplaceBar::_replace_all() {
set_error(vformat(TTR("Replaced %d occurrence(s)."), rc));
text_edit->call_deferred("connect", "text_changed", this, "_editor_text_changed");
+ results_count = -1;
}
void FindReplaceBar::_get_search_from(int &r_line, int &r_col) {
@@ -297,6 +302,36 @@ void FindReplaceBar::_get_search_from(int &r_line, int &r_col) {
}
}
+void FindReplaceBar::_update_results_count() {
+ if (results_count != -1)
+ return;
+
+ results_count = 0;
+
+ String searched = get_search_text();
+ if (searched.empty()) return;
+
+ String full_text = text_edit->get_text();
+
+ int from_pos = 0;
+
+ while (true) {
+ int pos = is_case_sensitive() ? full_text.find(searched, from_pos) : full_text.findn(searched, from_pos);
+ 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]))
+ continue;
+ if (pos + searched.length() < full_text.length() && !is_symbol(full_text[pos + searched.length()]))
+ continue;
+ }
+
+ results_count++;
+ from_pos = pos + searched.length();
+ }
+}
+
bool FindReplaceBar::search_current() {
uint32_t flags = 0;
@@ -420,11 +455,13 @@ void FindReplaceBar::popup_replace() {
void FindReplaceBar::_search_options_changed(bool p_pressed) {
+ results_count = -1;
search_current();
}
void FindReplaceBar::_editor_text_changed() {
+ results_count = -1;
if (is_visible_in_tree()) {
preserve_cursor = true;
search_current();
@@ -434,6 +471,7 @@ void FindReplaceBar::_editor_text_changed() {
void FindReplaceBar::_search_text_changed(const String &p_text) {
+ results_count = -1;
search_current();
}
@@ -486,6 +524,7 @@ void FindReplaceBar::set_error(const String &p_label) {
void FindReplaceBar::set_text_edit(TextEdit *p_text_edit) {
+ results_count = -1;
text_edit = p_text_edit;
text_edit->connect("text_changed", this, "_editor_text_changed");
}
@@ -512,6 +551,7 @@ void FindReplaceBar::_bind_methods() {
FindReplaceBar::FindReplaceBar() {
+ results_count = -1;
replace_all_mode = false;
preserve_cursor = false;
@@ -1387,17 +1427,17 @@ void CodeTextEditor::_on_settings_change() {
// AUTO BRACE COMPLETION
text_editor->set_auto_brace_completion(
- EDITOR_DEF("text_editor/completion/auto_brace_complete", true));
+ EDITOR_GET("text_editor/completion/auto_brace_complete"));
code_complete_timer->set_wait_time(
- EDITOR_DEF("text_editor/completion/code_complete_delay", .3f));
+ EDITOR_GET("text_editor/completion/code_complete_delay"));
// call hint settings
text_editor->set_callhint_settings(
- EDITOR_DEF("text_editor/completion/put_callhint_tooltip_below_current_line", true),
- EDITOR_DEF("text_editor/completion/callhint_tooltip_offset", Vector2()));
+ EDITOR_GET("text_editor/completion/put_callhint_tooltip_below_current_line"),
+ EDITOR_GET("text_editor/completion/callhint_tooltip_offset"));
- idle->set_wait_time(EDITOR_DEF("text_editor/completion/idle_parse_delay", 2.0));
+ idle->set_wait_time(EDITOR_GET("text_editor/completion/idle_parse_delay"));
}
void CodeTextEditor::_text_changed_idle_timeout() {
@@ -1583,12 +1623,12 @@ CodeTextEditor::CodeTextEditor() {
idle = memnew(Timer);
add_child(idle);
idle->set_one_shot(true);
- idle->set_wait_time(EDITOR_DEF("text_editor/completion/idle_parse_delay", 2.0));
+ idle->set_wait_time(EDITOR_GET("text_editor/completion/idle_parse_delay"));
code_complete_timer = memnew(Timer);
add_child(code_complete_timer);
code_complete_timer->set_one_shot(true);
- code_complete_timer->set_wait_time(EDITOR_DEF("text_editor/completion/code_complete_delay", .3f));
+ code_complete_timer->set_wait_time(EDITOR_GET("text_editor/completion/code_complete_delay"));
error_line = 0;
error_column = 0;