Skip to content

Commit

Permalink
GH-521 Fix compatibility issue with Godot 4.2.1 and containsn
Browse files Browse the repository at this point in the history
  • Loading branch information
Naros committed Jul 14, 2024
1 parent 52a1884 commit d6b9352
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/editor/property_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "common/property_utils.h"
#include "common/scene_utils.h"
#include "common/variant_utils.h"
#include "common/version.h"

#include <godot_cpp/classes/button.hpp>
#include <godot_cpp/classes/input_event_key.hpp>
Expand Down Expand Up @@ -84,6 +85,15 @@ void OrchestratorPropertySelector::_item_selected()
// Leaving for now in case EditorHelpBit gets exposed
}

bool OrchestratorPropertySelector::_contains_ignore_case(const String& p_text, const String& p_what) const
{
#if GODOT_VERSION >= 0x040300
return p_text.containsn(p_what);
#else
return p_text.to_lower().contains(p_what.to_lower());
#endif
}

void OrchestratorPropertySelector::_update_search()
{
_search_options->clear();
Expand Down Expand Up @@ -126,7 +136,7 @@ void OrchestratorPropertySelector::_update_search()
if (!(E.usage & PROPERTY_USAGE_EDITOR) && !(E.usage & PROPERTY_USAGE_SCRIPT_VARIABLE))
continue;

if (!_search_box->get_text().is_empty() && !E.name.containsn(search_text))
if (!_search_box->get_text().is_empty() && !_contains_ignore_case(E.name, search_text))
continue;

if (_type_filter.size() && !_type_filter.has(E.type))
Expand All @@ -137,12 +147,12 @@ void OrchestratorPropertySelector::_update_search()
item->set_metadata(0, E.name);
item->set_icon(0, SceneUtils::get_class_icon(PropertyUtils::get_variant_type_name(E)));

if (!found & !_search_box->get_text().is_empty() && E.name.containsn(search_text))
if (!found & !_search_box->get_text().is_empty() && _contains_ignore_case(E.name, search_text))
{
item->select(0);
found = true;
}
else if (!found && _search_box->get_text().is_empty() && E.name.containsn(_selected))
else if (!found && _search_box->get_text().is_empty() && _contains_ignore_case(E.name, _selected))
{
item->select(0);
found = true;
Expand Down
5 changes: 5 additions & 0 deletions src/editor/property_selector.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class OrchestratorPropertySelector : public ConfirmationDialog
void _item_selected();
//~ End Signal Handlers

/// Checks whether the text contains the what
/// @param p_text the text to search
/// @param p_what what to search
bool _contains_ignore_case(const String& p_text, const String& p_what) const;

/// Updates the search options based on the filter
void _update_search();

Expand Down

0 comments on commit d6b9352

Please sign in to comment.