Please correct me if I’m overlooking this feature already.
I would love the ability to focus the project where my text insertion point is currently. (And to then unfocus back out again while still showing the project that had just been focused.)
In the meanwhile, to toggle the hoisting of the project containing the cursor, you should be able to attach this to a keystroke (or put it in a Keyboard Maestro JXA action)
// TOGGLE HOISTING OF PROJECT CONTAINING CURSOR
// v 0.3
(function () {
'use strict';
// TASKPAPER 3 EVALUATION CONTEXT
function projectHoistToggle(editor) {
// selection ?
var rngSeln = editor.getSelectedItemRange(),
oSeln = rngSeln ? rngSeln.startItem : null,
// containing project ?
lstSelnProj = oSeln ? oSeln.evaluateItemPath(
'(ancestor-or-self::@type=project)[-1]'
) : [],
blnSelnInProj = lstSelnProj.length;
// toggle hoist state if selection is in project
if (blnSelnInProj) {
editor.hoist(
editor.getHoistedItem().isRoot ? lstSelnProj[0] :
editor.itemBuffer.outline.root
);
// restore selection after toggling hoist
editor.setSelectedItemRange(rngSeln);
}
// Let Script Editor context know if we have toggled
return blnSelnInProj;
}
// OS X SCRIPT EDITOR EVALUATION CONTEXT
var tp = Application("TaskPaper"),
ds = tp.documents;
// if selection is in a project,
// toggle hoist and then activate TaskPaper app
return ds.length ? ds[0].evaluate({
script: projectHoistToggle.toString()
}) && tp.activate() : false;
})();
Thanks – there are a couple of API details which changed after that script was written. It could now, I think, be written something like the redraft below.
// TOGGLE HOISTING OF PROJECT CONTAINING CURSOR
// v 0.4
(function () {
'use strict';
// TASKPAPER 3 EVALUATION CONTEXT
function projectHoistToggle(editor) {
var outline = editor.outline,
selection = editor.selection,
dctSeln = {
startItem: selection.startItem,
startOffset: selection.startOffset,
endItem: selection.endItem,
endOffset: selection.endOffset
}
// containing project ?
lstSelnProj = dctSeln.startItem ? outline.evaluateItemPath(
'(ancestor-or-self::@type=project)[-1]',
dctSeln.startItem
) : [],
blnSelnInProj = lstSelnProj.length;
// toggle hoist state if selection is in project
if (blnSelnInProj) {
editor.hoist(
editor.hoistedItem.isOutlineRoot ? lstSelnProj[0] :
outline.root
);
// restore selection after toggling hoist
editor.moveSelectionToItems(
dctSeln.startItem,
dctSeln.startOffset,
dctSeln.endItem,
dctSeln.endOffset
);
}
// Let Script Editor context know if we have toggled
return blnSelnInProj;
}
// OS X SCRIPT EDITOR EVALUATION CONTEXT
var tp = Application("TaskPaper"),
ds = tp.documents;
// if selection is in a project,
// toggle hoist and then activate TaskPaper app
return ds.length ? ds[0].evaluate({
script: projectHoistToggle.toString()
}) && tp.activate() : false;
})();
TypeError: sln.evaluateItemPath is not a function. (In 'sln.evaluateItemPath(
'ancestor-or-self::@type=project[-1]'
)', 'sln.evaluateItemPath' is undefined)
fn
evaluateScript@file:///Applications/TaskPaper.app/Contents/Resources/dist/birch.js:53025:16
Use the Help > SDKRunner to debug