Skip to content

Commit bd6c14f

Browse files
dzj0821minggo
authored andcommitted
in Node::enumerateChildren, searchFromParent shouldn't search from children (#20007)
* searchFromParent shouldn't search from grand children
1 parent ec4ebb6 commit bd6c14f

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

cocos/2d/CCNode.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -850,22 +850,27 @@ void Node::enumerateChildren(const std::string &name, const std::function<bool (
850850

851851
// Remove '//', '/..' if exist
852852
std::string newName = name.substr(subStrStartPos, subStrlength);
853-
853+
854+
const Node* target = this;
855+
854856
if (searchFromParent)
855857
{
856-
newName.insert(0, "[[:alnum:]]+/");
858+
if (nullptr == _parent)
859+
{
860+
return;
861+
}
862+
target = _parent;
857863
}
858864

859-
860865
if (searchRecursively)
861866
{
862867
// name is '//xxx'
863-
doEnumerateRecursive(this, newName, callback);
868+
target->doEnumerateRecursive(this, newName, callback);
864869
}
865870
else
866871
{
867872
// name is xxx
868-
doEnumerate(newName, callback);
873+
target->doEnumerate(newName, callback);
869874
}
870875
}
871876

cocos/2d/CCNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ class CC_DLL Node : public Ref
812812
* @param name The name to search for, supports c++11 regular expression.
813813
* Search syntax options:
814814
* `//`: Can only be placed at the begin of the search string. This indicates that it will search recursively.
815-
* `..`: The search should move up to the node's parent. Can only be placed at the end of string.
815+
* `/..`: The search should move up to the node's parent. Can only be placed at the end of string.
816816
* `/` : When placed anywhere but the start of the search string, this indicates that the search should move to the node's children.
817817
*
818818
* @code

0 commit comments

Comments
 (0)