In Adobe XD, I am trying to get all the parts of text that match a regular expression. However, text that should be matched by matchAll, RegExp.exec, etc. is frequently ignored.
It seems to be happening when I use regular expressions too often in a row along with the filter function. Does this reproduce in your environment? Is there a workaround?
Failing code
const noMatchSample = async () => {
const searchPattern = /text/g ;
const targetTextFrames = selection.items.filter((aItem) => {
// this area affects failure
return (
/^Text$/.test(aItem.constructor.name)
&& searchPattern.test(aItem.text)
)
}) ;
targetTextFrames.forEach((currentTextFrame) => {
/* …some processing here… */
const matches = currentTextFrame.text.matchAll(searchPattern) ; // at this time it is quietly failing and is ignored
for(const aMatch of matches) {
console.log(aMatch) ;
}
}) ;
} ;
Successful code
const matchSample = async () => {
const searchPattern = /text/g ;
const targetTextFrames = selection.items.filter((aItem) => {
// remove regular expressions from this area
return (
aItem.constructor.name === 'Text'
)
}) ;
targetTextFrames.forEach((currentTextFrame) => {
/* …some processing here… */
const matches = currentTextFrame.text.matchAll(searchPattern) ; // succeed
for(const aMatch of matches) {
console.log(aMatch) ;
}
}) ;
} ;
Document state
Three text frames are selected.
Environment
- Adobe XD 54.1.12.1 arm64
- macOS 11.6.8 (Apple Silicon)