解決済み
replace textlayer content with prompt search and change specific words colors
Greetings to everyone
I have this code but it has a problem
var searchWord = prompt("Enter the word to search for:", "", "Search Word");
var textColor = new SolidColor();
textColor.rgb.red = 255;
textColor.rgb.green = 0;
textColor.rgb.blue = 0;
var activeLayer = app.activeDocument.activeLayer;
if (activeLayer.kind === LayerKind.TEXT) {
var textItem = activeLayer.textItem;
var textContents = textItem.contents;
var txt = activeDocument.activeLayer.textItem.contents.toLowerCase(); // "blablablabla Sport blablablabla sport blablabla Sports";
var idx = [];
var newTextContents = textContents.replace(new RegExp(searchWord, 'gi'),+ searchWord );
//var idx = searchWord;
for (var i = 0; i < searchWord.length; i++)
searchWord[i].color = textColor;
textItem.contents = newTextContents;
//textItem.color = textColor;
}
I search for a word within a text layer, but when I use the code, I see results (Nan)
I want to modify the code to show the search results and change the color of the search results words to red

