Question
expression selector help...
Hey, I'm trying to get a text expression selector to just select the last 2 characters or each line in a block of text, this is what I have so far...
// Get the total number of characters in the text layer
totalChars = text.sourceText.length;
// Replace line breaks with a consistent character
textContent = text.sourceText.replace(/[\r\n]+/g, '\n');
// Get the number of characters in the current line
currentLine = textContent.slice(0, textIndex).split("\n").length;
lineStartIndex = textContent.lastIndexOf("\n", textIndex - 1) + 1;
lineEndIndex = textContent.indexOf("\n", textIndex);
if (lineEndIndex == -1) lineEndIndex = totalChars;
// Calculate the position of the last two characters in the current line
lastCharPos = lineEndIndex - lineStartIndex - (currentLine - 1);
secondLastCharPos = lastCharPos - 1;
// Check if the current character is one of the last two characters in the line
if (textIndex - lineStartIndex == secondLastCharPos || textIndex - lineStartIndex == lastCharPos) {
100;
} else {
0;
}
which works for the first 12 lines (I have 16 lines in total), then stops working?
Any ideas why its failing aster 12 lines?
Ta
Pete
