Mystery bug when searching documents using JavaScript

@jessegrosjean or @complexpoint

Okay, I noticed that some of the search functions do not turn the same results when they are processed through JavaScript editor.outline.evaluateItemPath() instead of TaskPaper.

Let’s use this example. I want to hide all the elements and their children if those elements are tagged with @private.

First project:
	- One
	- Two
	- Three
Second project: @private
	- One
	- Two
	- Three
Third project:
	- One
	- Two @private
	- Three
Fourth project:
	- One
	- Two @private
	- Three
Fifth project:
	- One
	- Two @private
	- Three
Sixth project:
	- One
	- Two
	- Three
Seventh project:
	- One
	- Two
	- Three
	Subproject:
		- One
		- Two @private
		- Three
Eighth project:
	- One
	- Two
	- Three
	Subproject: @private
		- One
		- Two
		- Three
Ninth project:
	- One
	- Two
	- Three
Tenth project:
	- One @private
	- Two @private
	- Three @private

My first idea would be to do something like this.

task except (( //@private/ancestor::* union @private///*) union (archive///* union @done///*))

Now, if you are reading this because of curiosity but you would like to learn what the following does ( //@private/ancestor::* union @private///*) doing, let me quickly explain it.

  1. @private///* Hides taskpaper elements and all of their children if the elements are tagged with @private.
  2. //@private/ancestor::* Is kind of a cool hack. This hides all of the element’s ancestors if that element is tagged with @private. Because TaskPaper always returns all of the ancestors if it find a true statement, what this accomplishes is to hide the ancestors ONLY if there are no more elements within those ancestors tagged with @private. In my example, the tenth project will not be presented because ALL of its children are tagged with @private.

Now, if I try to run that using Javascript

editor.outline.evaluateItemPath(task except (( //@private/ancestor::* union @private///*) union (archive///* union @done///*)))

I truly only get the tasks. The parent elements simply disappear. I assumed this had with the fact that the script is not limited the way that TaskPaper is. My work around for this particular idiosyncrasy is to introduce the parents into the query. Either of these queries will kind of work

(@type/ancestor::* union task///*) except (( //@private/ancestor::* union @private///*) union (archive///* union @done///*))

Or just like the following query using the parents instead of all of the ancestors. Logically it seems to make no difference in this particular case because once a child is introduced, the rest of the ancestors seem to also appear even when using the script.

(@type/..* union task///*) except (( //@private/..* union @private///*) union (archive///* union @done///*))

Running this ALMOST works. There just seems to be a bug in the editor.outline.evaluateItemPath() This is what happens.

  1. If the parent of the private element is preceded by a parent not caught by the private exception then it DOESN’t appear in the results.
  2. The following parent with a private element DOES appear if it follows another parent of a private element.
  3. This problem appears again if there is another parent of a private element following #2

In other words. This is the expected result of the query,

First project:
	- One
	- Two
	- Three
Third project:
	- One
	- Three
Fourth project:
	- One
	- Three
Fifth project:
	- One
	- Three
Sixth project:
	- One
	- Two
	- Three
Seventh project:
	- One
	- Two
	- Three
	Subproject:
		- One
		- Three
Eighth project:
	- One
	- Two
	- Three
Ninth project:
	- One
	- Two
	- Three

But this is what we get instead

First project:
	- One
	- Two
	- Three
	- One
	- Three
Fourth project:
	- One
	- Three
	- One
	- Three
Sixth project:
	- One
	- Two
	- Three
Seventh project:
	- One
	- Two
	- Three
		- One
		- Three
Eighth project:
	- One
	- Two
	- Three
Ninth project:
	- One
	- Two
	- Three

Any ideas why? This is the script I am using to create a new TaskPaper document