Skip to content

Commit

Permalink
Fix a bug where renaming project elements wouldn't work when an actio…
Browse files Browse the repository at this point in the history
…n is using the default layer (#5524)
  • Loading branch information
ClementPasteau authored Aug 2, 2023
1 parent 075cc5a commit f95d197
Show file tree
Hide file tree
Showing 5 changed files with 751 additions and 757 deletions.
257 changes: 130 additions & 127 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,131 +1,134 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.associations": {
"*.idl": "java",
"Fastfile": "ruby",
"iosfwd": "cpp",
"functional": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"algorithm": "cpp",
"random": "cpp",
"__config": "cpp",
"cstddef": "cpp",
"exception": "cpp",
"initializer_list": "cpp",
"new": "cpp",
"stdexcept": "cpp",
"typeinfo": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"complex": "cpp",
"cstdarg": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"istream": "cpp",
"limits": "cpp",
"memory": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"streambuf": "cpp",
"hashtable": "cpp",
"tuple": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"__split_buffer": "cpp",
"deque": "cpp",
"iterator": "cpp",
"list": "cpp",
"map": "cpp",
"queue": "cpp",
"regex": "cpp",
"set": "cpp",
"stack": "cpp",
"string": "cpp",
"vector": "cpp",
"iostream": "cpp",
"__functional_03": "cpp",
"__hash_table": "cpp",
"__tree": "cpp",
"bitset": "cpp",
"__bit_reference": "cpp",
"__mutex_base": "cpp",
"fstream": "cpp",
"ios": "cpp",
"__locale": "cpp",
"valarray": "cpp",
"freeglut_spaceball.c": "cpp",
"__tuple": "cpp",
"hash_map": "cpp",
"hash_set": "cpp",
"system_error": "cpp",
"__nullptr": "cpp",
"__functional_base": "cpp",
"__functional_base_03": "cpp",
"chrono": "cpp",
"ratio": "cpp",
"atomic": "cpp",
"locale": "cpp",
"string_view": "cpp",
"__string": "cpp",
"cstring": "cpp",
"iomanip": "cpp",
"cstdint": "cpp",
"forward_list": "cpp",
"mutex": "cpp",
"__hash": "cpp",
"__debug": "cpp",
"__threading_support": "cpp",
"any": "cpp",
"array": "cpp",
"cinttypes": "cpp",
"numeric": "cpp",
"__memory": "cpp",
"__errc": "cpp",
"__node_handle": "cpp",
"bit": "cpp",
"optional": "cpp",
"filesystem": "cpp",
"compare": "cpp",
"concepts": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocinfo": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"xlocbuf": "cpp",
"xlocmes": "cpp",
"xmemory0": "cpp",
"memory_resource": "cpp"
},
"files.exclude": {
"Binaries/*build*": true,
"Binaries/Output": true,
"GDJS/Runtime-dist": true,
"docs": true,
"newIDE/electron-app/dist": true,
"newIDE/app/build": true,
"newIDE/app/resources/GDJS": true,
"newIDE/electron-app/app/www": true
},
// Support for Flowtype (for newIDE):
"javascript.validate.enable": false,
"flow.useNPMPackagedFlow": true,
"files.associations": {
"*.idl": "java",
"Fastfile": "ruby",
"iosfwd": "cpp",
"functional": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"algorithm": "cpp",
"random": "cpp",
"__config": "cpp",
"cstddef": "cpp",
"exception": "cpp",
"initializer_list": "cpp",
"new": "cpp",
"stdexcept": "cpp",
"typeinfo": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"complex": "cpp",
"cstdarg": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"istream": "cpp",
"limits": "cpp",
"memory": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"streambuf": "cpp",
"hashtable": "cpp",
"tuple": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"__split_buffer": "cpp",
"deque": "cpp",
"iterator": "cpp",
"list": "cpp",
"map": "cpp",
"queue": "cpp",
"regex": "cpp",
"set": "cpp",
"stack": "cpp",
"string": "cpp",
"vector": "cpp",
"iostream": "cpp",
"__functional_03": "cpp",
"__hash_table": "cpp",
"__tree": "cpp",
"bitset": "cpp",
"__bit_reference": "cpp",
"__mutex_base": "cpp",
"fstream": "cpp",
"ios": "cpp",
"__locale": "cpp",
"valarray": "cpp",
"freeglut_spaceball.c": "cpp",
"__tuple": "cpp",
"hash_map": "cpp",
"hash_set": "cpp",
"system_error": "cpp",
"__nullptr": "cpp",
"__functional_base": "cpp",
"__functional_base_03": "cpp",
"chrono": "cpp",
"ratio": "cpp",
"atomic": "cpp",
"locale": "cpp",
"string_view": "cpp",
"__string": "cpp",
"cstring": "cpp",
"iomanip": "cpp",
"cstdint": "cpp",
"forward_list": "cpp",
"mutex": "cpp",
"__hash": "cpp",
"__debug": "cpp",
"__threading_support": "cpp",
"any": "cpp",
"array": "cpp",
"cinttypes": "cpp",
"numeric": "cpp",
"__memory": "cpp",
"__errc": "cpp",
"__node_handle": "cpp",
"bit": "cpp",
"optional": "cpp",
"filesystem": "cpp",
"compare": "cpp",
"concepts": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocinfo": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"xlocbuf": "cpp",
"xlocmes": "cpp",
"xmemory0": "cpp",
"memory_resource": "cpp",
"__bits": "cpp",
"__verbose_abort": "cpp",
"variant": "cpp"
},
"files.exclude": {
"Binaries/*build*": true,
"Binaries/Output": true,
"GDJS/Runtime-dist": true,
"docs": true,
"newIDE/electron-app/dist": true,
"newIDE/app/build": true,
"newIDE/app/resources/GDJS": true,
"newIDE/electron-app/app/www": true
},
// Support for Flowtype (for newIDE):
"javascript.validate.enable": false,
"flow.useNPMPackagedFlow": true,

// Clang format styling (duplicated in scripts/CMakeClangUtils.txt)
"C_Cpp.clang_format_style": "{BasedOnStyle: Google, BinPackParameters: false, BinPackArguments: false}"
// Clang format styling (duplicated in scripts/CMakeClangUtils.txt)
"C_Cpp.clang_format_style": "{BasedOnStyle: Google, BinPackParameters: false, BinPackArguments: false}"
}
34 changes: 25 additions & 9 deletions Core/GDCore/IDE/Events/ProjectElementRenamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,22 @@ class GD_CORE_API ExpressionIdentifierStringFinder
std::unique_ptr<gd::ExpressionNode> &parameterNode,
size_t parameterIndex, const gd::String &lastObjectName) {
if (parameterMetadata.GetType() == "layer") {
// Remove quotes, it won't match if it's not a literal anyway.
lastLayerName = expressionPlainString.substr(
parameterNode->location.GetStartPosition() + 1,
parameterNode->location.GetEndPosition() -
parameterNode->location.GetStartPosition() - 2);
if (parameterNode->location.GetEndPosition() -
parameterNode->location.GetStartPosition() <
2) {
// This is either the base layer or an invalid layer name.
// Keep it as is.
lastLayerName = expressionPlainString.substr(
parameterNode->location.GetStartPosition(),
parameterNode->location.GetEndPosition() -
parameterNode->location.GetStartPosition());
} else {
// Remove quotes, so it can be compared to the layer name.
lastLayerName = expressionPlainString.substr(
parameterNode->location.GetStartPosition() + 1,
parameterNode->location.GetEndPosition() -
parameterNode->location.GetStartPosition() - 2);
}
}
if (parameterMetadata.GetType() == parameterType) {
auto parameterExpressionPlainString = expressionPlainString.substr(
Expand Down Expand Up @@ -143,9 +154,15 @@ bool ProjectElementRenamer::DoVisitInstruction(gd::Instruction &instruction,
const gd::Expression &parameterValue, size_t parameterIndex,
const gd::String &lastObjectName) {
if (parameterMetadata.GetType() == "layer") {
// Remove quotes, it won't match if it's not a literal anyway.
lastLayerName = parameterValue.GetPlainString().substr(
1, parameterValue.GetPlainString().length() - 2);
if (parameterValue.GetPlainString().length() < 2) {
// This is either the base layer or an invalid layer name.
// Keep it as is.
lastLayerName = parameterValue.GetPlainString();
} else {
// Remove quotes, so it can be compared to the layer name.
lastLayerName = parameterValue.GetPlainString().substr(
1, parameterValue.GetPlainString().length() - 2);
}
}

if (parameterMetadata.GetType() == parameterType &&
Expand All @@ -165,7 +182,6 @@ bool ProjectElementRenamer::DoVisitInstruction(gd::Instruction &instruction,
node->Visit(finder);

if (finder.GetOccurrences().size() > 0) {

gd::String newNameWithQuotes = "\"" + newName + "\"";
gd::String oldParameterValue = parameterValue.GetPlainString();
gd::String newParameterValue;
Expand Down
Loading

0 comments on commit f95d197

Please sign in to comment.