Copy link to clipboard
Copied
Hi
I want to remove one character from insertionPoint.
I tried below code. But It was not able to get the results I want.
Please advice for me.
Thanks.
//app.selection[0].remove(); // "app.selection[0]" is current insertionPoint.
//app.selection[0].characters[0].remove();
//app.selection[0].texts[0].remove();
1 Correct answer
It's a little trickier than you might have thought:
app.selection[0].parent.characters[app.selection[0].index - 1].remove()
In other words, first you find the parent story of the insertionPoint. Then you find the nth character of that story, n being the index of the selected insertionPoint. Then subtract 1, as you want to delete backwards, so you want the character before the insertionPoint.
Ariel
Copy link to clipboard
Copied
It's a little trickier than you might have thought:
app.selection[0].parent.characters[app.selection[0].index - 1].remove()
In other words, first you find the parent story of the insertionPoint. Then you find the nth character of that story, n being the index of the selected insertionPoint. Then subtract 1, as you want to delete backwards, so you want the character before the insertionPoint.
Ariel
Copy link to clipboard
Copied
Following should work for you. I have considered that you do not have linked text frames, i.e, you story is contained in one text frame only.
var selectionContext = app.selection[0];
if(selectionContext && selectionContext.constructor.name == "InsertionPoint") { // Make sure it is insertion point only
var index = selectionContext.index;
if(selectionContext.parent.constructor.name == "Story") {
var ch = selectionContext.parent.characters.item(index); // Make sure we have a char to delete
if(ch && ch.isValid)
ch.remove();
}
}
Copy link to clipboard
Copied
Thanks for your answer
Copy link to clipboard
Copied
Hello vinothr,
the parent of the insertionPoint could be also: "[object Cell]" or "[object Footnote]".
Uwe
Copy link to clipboard
Copied
Yes, agree, perhaps, depending on the context, parent of InsertionPoint can be TextPath, Text, TextFrame, Paragraph, Word, Cell, Note, XMLElement, HiddenText, etc.
Line 4 can be removed

