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?
app.selection.words 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;
var story = sel.parentStory;
var curWord = sel.words;
var curWordIndex = curWord.index;
prevWord = story.characters.item(curWordIndex-2).words;
You can then use move to move the words around, but you will probably need to deal with the spaces as well...
This is sorta the track I was on. The problem I'm seeing is that the "index" value is in terms of characters...not the words that it's expecting. So, for example, I'm on word #170, but the index value is #978...so when it tries to operate on word #978 it doesn't exist and blows up.