To toggle hoisting of the project containing the cursor in TaskPaper 3 Preview
Toggle hoist TP3 project containing cursor.kmmacros (19.5 KB)
// TOGGLE HOISTING OF PROJECT CONTAINING CURSOR
// v 0.3
(function () {
'use strict';
function projectHoistToggle(editor) {
var rngSeln = editor.getSelectedItemRange(),
oSeln = rngSeln ? rngSeln.startItem : null;
if (!editor.getHoistedItem().isRoot) {
editor.hoist(editor.itemBuffer.outline.root);
} else {
var lstProject = oSeln ? oSeln.evaluateItemPath(
'(ancestor-or-self::@type=project)[-1]'
) : [];
if (lstProject.length) editor.hoist(lstProject[0]);
}
return rngSeln ? editor.setSelectedItemRange(
rngSeln
) : false;
}
var tp = Application("TaskPaper"),
ds = tp.documents;
return ds.length ? ds[0].evaluate({
script: projectHoistToggle.toString()
}) && tp.activate() : false;
})();