I believe this is a bug, but if not can anyone explain why occasionally Photoshop will return duplicate textStyleRanges
when getting the text info with Batch Play?
In the attached example PSD there should be 4 groups, however the command is returning 5 groups, but the first 2 groups are identical with the same from/to ranges.
Text layer, contains 4 groups
BatchPlay returning 5 textStyleRanges
Example PSD:
text-group-issue.zip (30.4 KB)
Snippet to get text value with Batch Play:
(ensure example doc is open and text layer is selected)
const photoshop = require('photoshop');
const { executeAsModal } = photoshop.core;
const { batchPlay } = photoshop.action;
const getText = async (layer) => {
let existingText = await executeAsModal(
async () => {
const res = await batchPlay(
[
{
_obj: "get",
_target: [
{
_ref: "layer",
_id: layer.id,
},
],
_options: {
dialogOptions: "dontDisplay",
},
},
],
{}
);
return res[0].textKey;
},
{ commandName: "Get Text" }
);
return existingText;
};
await getText(photoshop.app.activeDocument.activeLayers[0]);
We can fix this by deleting the problem text in the text layer and recreating it from scratch, but it seems like there’s an underlying bug with PS allowing duplicate textStyleRanges.
Example Corrected PSD after deleting and re-creating text in text layer
(now reports 4 groups as it should)
text-group-issue-corrected.zip (30.5 KB)