I am trying to write a JavaScript to transpose adjacent words.
I plan to use the "move" function but am having trouble getting a reference to the word under the cursor.
I can find out which character I am in within the story...but don't think I should need to iterate through all of the characters in the story to determine the word number.
Can someone provide some guidance on how I can determine the number of the word under the cursor?
Thanks much!
app.selection[0].words[0] gives you a reference to the word.
You can use story.words.previousItem(word) to get the previous one.
It's probably faster to work it out based on character indexes though.
Something like this:
var sel = app.selection[0];
var story = sel.parentStory;
var curWord = sel.words[0];
var curWordIndex = curWord.index;
prevWord = story.characters.item(curWordIndex-2).words[0];
You can then use move to move the words around, but you will probably need to deal with the spaces as well...
Harbs
North America
Europe, Middle East and Africa
Asia Pacific