Script to move cursor into editor from sidebar


#1

This Alfred workflow runs the following inside TaskPaper to show and move the cursor to an item given it’s id.

function TPContext(editor, options) {
    editor.itemPathFilter = ''
    var item = editor.outline.evaluateItemPath('@id = ' + options.id)[0]
    editor.forceDisplayed(item, true)
    editor.moveSelectionToItems(item)
}

It seems work well, but will not move the curser from the sidebar if I’ve just selected a project or saved search with it. Hitting Tab will then move the cursor to the item which must have been selected properly behind the scenes.

So, is there a way to force the cursor from the sidebar into the editor?


#2

If I understand you I think you want:

editor.focus()

It’s an undocumented method right now, but I’ll make it public if it solves the problem. Let me know.

Also in your script you could make it a little simpler by using:

editor.outline.getItemForID(options.id)

Instead of evaluateItemPath.


#3

Thanks Jesse. This is exactly what I want and it works great. Thanks also for the getItemForID hint. For reference I’ve ended up with:

// Show an item in TaskPaper and clear path filter
function TPContext(editor, options) {
    var item = editor.outline.getItemForID(options.id)
    editor.itemPathFilter = ''
    editor.forceDisplayed(item, true)
    editor.moveSelectionToItems(item)
    editor.focus()
}