refactor: use better whitespace-test for backdrops too

This commit is contained in:
jokebookservice1 2018-10-10 19:45:36 +01:00
parent 1a7ce093c3
commit 0c18b4952d
No known key found for this signature in database
GPG key ID: A872407E9C478467

View file

@ -403,8 +403,10 @@ class Scratch3LooksBlocks {
if (selectedIndex === stage.currentCostume) selectedIndex += 1;
stage.setCostume(selectedIndex);
}
} else if (!isNaN(requestedBackdrop) &&
(typeof requestedBackdrop !== 'string' || /\d/g.test(requestedBackdrop))) {
// Try to cast the string to a number (and treat it as a costume index)
// Pure whitespace should not be treated as a number (JS casts this to 0)
// Note: isNaN will cast the string to a number before checking if it's NaN
} else if (!(isNaN(requestedBackdrop) || Cast.isWhiteSpace(requestedBackdrop))) {
stage.setCostume(optZeroIndex ? Number(requestedBackdrop) : Number(requestedBackdrop) - 1);
}
}