From ced33dfa30ebe95f14db481d63b4ba329112ee95 Mon Sep 17 00:00:00 2001 From: minggo Date: Wed, 16 Oct 2019 14:15:14 +0800 Subject: [PATCH 1/2] sync #20007 to v4 --- cocos/2d/CCNode.cpp | 15 ++++++++++----- cocos/2d/CCNode.h | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index 7ecf261ffe71..2a02dee304a6 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -809,22 +809,27 @@ void Node::enumerateChildren(const std::string &name, std::functiondoEnumerateRecursive(this, newName, callback); } else { // name is xxx - doEnumerate(newName, callback); + target->doEnumerate(newName, callback); } } diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 2f1dccd7b2a7..bbab0deef6f5 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -794,7 +794,7 @@ class CC_DLL Node : public Ref * @param name The name to search for, supports c++11 regular expression. * Search syntax options: * `//`: Can only be placed at the begin of the search string. This indicates that it will search recursively. - * `..`: The search should move up to the node's parent. Can only be placed at the end of string. + * `/..`: The search should move up to the node's parent. Can only be placed at the end of string. * `/` : When placed anywhere but the start of the search string, this indicates that the search should move to the node's children. * * @code From a4cb9e40b5e92b43679f3c7ffdb2c4eefb0d6c25 Mon Sep 17 00:00:00 2001 From: Nhan Khong <49646896+ktrongnhan@users.noreply.github.com> Date: Mon, 19 Aug 2019 09:23:52 +0700 Subject: [PATCH 2/2] Fixing a bug in Node::enumerateChildren (#20045) This patch fixes an issue that if both // (recursive enumeration) and .. (starting from parent node) are specified, Node::enumerateChildren does not honor the latter and starts searching from current node rather than parent node. --- cocos/2d/CCNode.cpp | 2 +- tests/cpp-tests/Classes/NodeTest/NodeTest.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index 2a02dee304a6..f203c62dc67d 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -824,7 +824,7 @@ void Node::enumerateChildren(const std::string &name, std::functiondoEnumerateRecursive(this, newName, callback); + target->doEnumerateRecursive(target, newName, callback); } else { diff --git a/tests/cpp-tests/Classes/NodeTest/NodeTest.cpp b/tests/cpp-tests/Classes/NodeTest/NodeTest.cpp index 64329357792d..3df31eee30dd 100644 --- a/tests/cpp-tests/Classes/NodeTest/NodeTest.cpp +++ b/tests/cpp-tests/Classes/NodeTest/NodeTest.cpp @@ -1395,14 +1395,14 @@ void NodeNameTest::test(float dt) // search from parent // name is xxx/.. i = 0; - parent->enumerateChildren("node/..", [&i](Node* node) -> bool { + parent->getChildByName("node1")->enumerateChildren("node[[:digit:]]+/node/..", [&i](Node* node) -> bool { ++i; return true; }); CCAssert(i == 1, ""); i = 0; - parent->enumerateChildren("node/..", [&i](Node* node) -> bool { + parent->getChildByName("node1")->enumerateChildren("node[[:digit:]]+/node/..", [&i](Node* node) -> bool { ++i; return false; }); @@ -1441,11 +1441,11 @@ void NodeNameTest::test(float dt) CCAssert(i == 1, ""); i = 0; - parent->enumerateChildren("//node[[:digit:]]+/..", [&i](Node* node) -> bool { + parent->getChildByName("node1")->enumerateChildren("//node[[:digit:]]+/..", [&i](Node* node) -> bool { ++i; return false; }); - CCAssert(i == 100, ""); + CCAssert(i == 110, ""); // utils::findChildren()