Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created December 23, 2022 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/e92703449e457b5327b1046c722f2c87 to your computer and use it in GitHub Desktop.
Save bjoerntx/e92703449e457b5327b1046c722f2c87 to your computer and use it in GitHub Desktop.
async function replaceSubTextParts(startsWithText) {
TXTextControl.subTextParts.getCount(async function(count) {
for (var i = count - 1; i >= 0; i--) {
await replaceText(i, startsWithText);
}
})
}
function replaceText(i, startsWithText) {
return new Promise(resolve => {
TXTextControl.subTextParts.elementAt(i, function(stp) {
stp.getName(function(name) {
if (name.startsWith(startsWithText)) {
stp.getStart(function(start) {
stp.getLength(function(length) {
TXTextControl.select(start - 1, length - 1, function() {
TXTextControl.selection.setText("Replaced SubTextPart Text");
TXTextControl.focus();
TXTextControl.clear();
resolve(true);
})
})
})
} else resolve(false);
})
})
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment