Copy link to clipboard
Copied
Hi, I select some text and use this two lines to add two characters before and after my selected text, it works but the selected text changes and includes one of the added characters. How can I add these tho characters and have the selection stay the same?
app.selection[0].insertionPoints[-1].contents = "\u0041"; | ||
app.selection[0].insertionPoints[0].contents = "\u0042"; |
Hi,
Store some properties before changes and use them:
var
mText = app.selection[0].texts[0],
len = mText.length;
mText.insertionPoints[-1].contents = "\u0041";
mText.insertionPoints[0].contents = "\u0042";
mText = app.selection[0].texts[0];
mText.characters.itemByRange(0,len-1).select();
Jarek
Copy link to clipboard
Copied
Hi,
Store some properties before changes and use them:
var
mText = app.selection[0].texts[0],
len = mText.length;
mText.insertionPoints[-1].contents = "\u0041";
mText.insertionPoints[0].contents = "\u0042";
mText = app.selection[0].texts[0];
mText.characters.itemByRange(0,len-1).select();
Jarek
Copy link to clipboard
Copied
Thank you!
Can I apply a certain character style to only these two added characters?
Copy link to clipboard
Copied
Hi,
A property 'index' can be helpful:
var
mText = app.selection[0].texts[0],
mIndex = mText.index,
len = mText.length,
mStory = mText.parentStory,
CSt1 = app.activeDocument.characterStyles.item("A"),
CSt2 = app.activeDocument.characterStyles.item("B");
mText.insertionPoints[-1].contents = "\u0041";
mText.insertionPoints[0].contents = "\u0042";
mText = app.selection[0].texts[0];
mStory.characters[mIndex].appliedCharacterStyle = CSt1;
mStory.characters[mIndex+len+1].appliedCharacterStyle = CSt2;
mText.characters.itemByRange(0,len-1).select();
Jarek
Copy link to clipboard
Copied
Thank you, it works on main text but doesn't apply the styles when i select some text in footnotes and run the script..
Copy link to clipboard
Copied
Hi,
because if you are using parentStory of a text selection in a footnote text you will get the story that is holding the footnote.
And not the footnote itself. For that you need simply parent. Same with text selected in table cells.
What should work (not tested):
mStory = mText.parent,
Regards,
Uwe
Copy link to clipboard
Copied
Yes, it works now
Thank you very much..