How to focus/zoom in at a given line number

Given that a file is open in TaskPaper, how do I make it “zoomin” at a particular line?

I wasn’t able to figure it out, but got a hacky solution in by using bash to get the contents of the file at that line and using taskpaper script to focus at that content, which is inideal (multiple lines could have the same content).

here’s what i have so far:

  const injectionScript = (editor, options) => {
    const outline = editor.outline,
      prjs = outline.evaluateItemPath('@text = "'+options.searchText.trim()+'"'),
      prj = prjs.length ? prjs[0] : undefined;

    if (prj) {
      const itemBufferOutline = editor.itemBuffer.outline,
        foundPrj = itemBufferOutline.getItemForID(prj.id);

      return foundPrj ? (
        editor['focusedItem'] = foundPrj,
          editor.moveSelectionToItems(foundPrj, options.charPos-1),
          foundPrj.bodyString
      ) : undefined;
    }
  }

intead, how do i get moveSelectionToItems to go to a certain line? thanks!

I’m not sure if this is what you want, but editor.outline.items returns an array of all items (lines) in document.

Can you just do editor.outline.items[lineNumber] to get the item you are interested in?

im not sure how to plug that into my system. how do i basically give it a line number and it “focuses” into whatever is at that line?

I think this does similar to what your script is doing, except using line numbers:

function TaskPaperContextScript(editor, options) {
	let item = editor.outline.items[options.lineNumber]
	if (item != null) {
		let project = item.ancestors.find(each => each.getAttribute('data-type') == 'project') || editor.outline.root
		editor.focusedItem = project
		editor.moveSelectionToItems(item, 0, item, -1)
	}
}

Application("TaskPaper").documents[0].evaluate({
  script: TaskPaperContextScript.toString(),
  withOptions: { lineNumber: 10 },
})
2 Likes

thank you! have a safe trip!