Alternate Collapse Behavior

Hi,

I noticed that if you collapse a task that has a parent and no children then it collapses that task and places the cursor on the parent. However if you try to collapse again on the parent nothing happens, even if it itself is a child with a parent.

Is there any way to use collapse in a manner where it keeps collapsing child objects, using the same key, until they have no parent.

i.e. in the example below if I start with my cursor on task 1.2.1.2 I could hit the collapse key 4 times and end up with the Project A: root collapsed.

Project A:
	- A Test task 1
		- A Test task 1.1
		- A Test task 1.2
			- A Test task 1.2.1
				- A Test task 1.2.1.1
				- A Test task 1.2.1.2

I don’t expect I’ll get to this soon, but I have added an issue to keep the idea around for a future release.

Ok, thanks for responding.

In the meantime :slight_smile: is there a way using applescript (or something similar) to determine whether or not the line that the cursor is on is already collapsed?

Yeah, this is an AppleScript that I think implements the behavior that you are after:

var TaskPaper = Application('TaskPaper')

function TPContextCollapse(editor, options) {
  var item = editor.selection.startItem
  if (!item.hasChildren || editor.isCollapsed(item)) {
  	var parent = item.parent
	if (editor.isDisplayed(parent)) {
	  	editor.setCollapsed(parent)
		editor.moveSelectionToItems(parent)
	}
  } else {
  	editor.setCollapsed(item)
  }
}

TaskPaper.documents[0].evaluate({
  script: TPContextCollapse.toString(),
  withOptions: { }
});

Awesome, that’s exactly the behavior I was after!!!

Just want to reiterate what I’m sure you’ve heard a lot but your outstanding support plus that of the taskpaper community are a large part of why I decided to make the switch.

Thx again!

2 Likes