Dealing with editing mode from omnijs plugin

I’ve written some plugin scripts that reorganize rows/items in various ways, and they are working great except in one case:

  • If I’m in editing mode (that is, have a live cursor in a row) when my plugin fires, the plugin is told that one item is selected, and I’m able to do my normal row manipulations successfully. However…

  • …the row doesn’t actually visually move to its new location in the editor until I leave editing mode (by pressing Cmd-Enter, typically), at which point it immediately snaps to its new location.

So, my questions are:

  1. Does anyone know of a way to immediately (visually, in the editor) move a row that’s in editing mode?

That would be best, but I’m not very hopeful it is possible. Barring that:

  1. Does anyone know of a way to detect that editing mode is active from an omnijs plugin?

If I could at least accomplish that, I could forbid the move, which would be fine for my purposes.

And even better than that would be:

  1. How about a way to get out of editing mode so I can properly move the row, and maybe even back into editing mode after the move?

Any thoughts are appreciated!

You can deselect a row by selecting another row, like this:

var editor = document.editors[0]
var node = editor.rootNode.children[0]
editor.select([node])

This script will deselect the active row and reselect the row:

var editor = document.editors[0]
var currentNodes = editor.selectedNodes
var node = editor.rootNode.children[0]
editor.select([node])
editor.select(currentNodes)

To exit “edit mode”:

var editor = document.editors[0]
editor.select([])