diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp index 2c4d2eec04b..9031fa1ace8 100644 --- a/core/object/script_language.cpp +++ b/core/object/script_language.cpp @@ -617,13 +617,13 @@ TypedArray ScriptLanguage::CodeCompletionOption::get_option_characteristics // Return characteristics of the match found by order of importance. // Matches will be ranked by a lexicographical order on the vector returned by this function. // The lower values indicate better matches and that they should go before in the order of appearance. - if (last_matches == matches) { + if (!matches_dirty) { return charac; } charac.clear(); // Ensure base is not empty and at the same time that matches is not empty too. if (p_base.length() == 0) { - last_matches = matches; + matches_dirty = false; charac.push_back(location); return charac; } @@ -642,7 +642,7 @@ TypedArray ScriptLanguage::CodeCompletionOption::get_option_characteristics charac.push_back(bad_case); charac.push_back(location); charac.push_back(matches[0].first); - last_matches = matches; + matches_dirty = false; return charac; } @@ -652,7 +652,7 @@ void ScriptLanguage::CodeCompletionOption::clear_characteristics() { TypedArray ScriptLanguage::CodeCompletionOption::get_option_cached_characteristics() const { // Only returns the cached value and warns if it was not updated since the last change of matches. - if (last_matches != matches) { + if (matches_dirty) { WARN_PRINT("Characteristics are not up to date."); } diff --git a/core/object/script_language.h b/core/object/script_language.h index e4c6427e7d1..d7bcfc73b3b 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -315,7 +315,7 @@ public: Ref icon; Variant default_value; Vector> matches; - Vector> last_matches = { { -1, -1 } }; // This value correspond to an impossible match + bool matches_dirty = true; // Must be set when mutating `matches`, so that sorting characteristics are recalculated. int location = LOCATION_OTHER; String theme_color_name; diff --git a/core/object/script_language_extension.h b/core/object/script_language_extension.h index cb114e05205..aef445ff7dd 100644 --- a/core/object/script_language_extension.h +++ b/core/object/script_language_extension.h @@ -427,6 +427,7 @@ public: option.matches.push_back(Pair(matches[j], matches[j + 1])); } } + option.matches_dirty = true; r_options->push_back(option); } } diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index 452c6a13b8d..ad4a8ad5ff1 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -3672,6 +3672,7 @@ void CodeEdit::_filter_code_completion_candidates_impl() { for (ScriptLanguage::CodeCompletionOption &option : code_completion_option_sources) { option.matches.clear(); + option.matches_dirty = true; if (single_quote && option.display.is_quoted()) { option.display = option.display.unquote().quote("'"); } @@ -3757,6 +3758,7 @@ void CodeEdit::_filter_code_completion_candidates_impl() { // go through all possible matches to get the best one as defined by CodeCompletionOptionCompare if (all_possible_subsequence_matches.size() > 0) { option.matches = all_possible_subsequence_matches[0]; + option.matches_dirty = true; option.get_option_characteristics(string_to_complete); all_possible_subsequence_matches = all_possible_subsequence_matches.slice(1); if (all_possible_subsequence_matches.size() > 0) { @@ -3765,6 +3767,7 @@ void CodeEdit::_filter_code_completion_candidates_impl() { compared_option.clear_characteristics(); for (Vector> &matches : all_possible_subsequence_matches) { compared_option.matches = matches; + compared_option.matches_dirty = true; compared_option.get_option_characteristics(string_to_complete); if (compare(compared_option, option)) { option = compared_option;