[Documentation Bug] The “Order of Tagged Tiddlers” documentation tiddler gives an incorrect description of the algorithm
Problem Description Per the function here: https://github.com/TiddlyWiki/TiddlyWiki5/blob/master/core/modules/wiki.js#L751C1-L751C49
Tiddlers are actually ordered like this when building a tag list:
- All tiddlers in the
listfield of the tagging tiddler are placed in an array. - All remaining tagged tiddlers that aren't in
listget placed alphabetically (arguably technically not “case-insensitively”; it useslocaleCompare()to build that list, which deterministically breaks ties by case; but this is probably too pedantic to be worth including) at the end. - TiddlyWiki goes through each tiddler in the list checking for
list-beforeandlist-afterfields, and moves the tiddler based on the first condition that obtains, if any (special case: if the tiddler has already been recursed into, as described in a moment, don't check it again):list-beforeempty -> to the start of the listlist-afterempty -> to the end of the listlist-beforepointing to a tiddler in the list -> before that tiddler – after first applying anylist-beforefield on the before-tiddler (recursively)list-afterpointing to a tiddler in the list -> after that tiddler – after first applying anylist-afterfield on the after-tiddler (recursively)
The documentation instead claims that it goes like this (my comments in [brackets]):
Start with any that are declared in the
listfield of the tag tiddler, in the order given there.In each remaining tiddler T [incorrect: it checks all tiddlers T tagged by the tiddler being evaluated, whether they were in the
listfield or not], look for alist-beforefield. If this has a tiddler title as its value, place T just before that one.- As a special case, if the field exists but its value is empty, place T at the very start of the list.
In each remaining tiddler T [incorrect: each tiddler is checked for
list-beforeandlist-afterfields simultaneously; this makes it sound like it makes two complete passes, one forbeforeand one forafter], look for alist-afterfield. If this has a tiddler title as its value, place tiddler T just after that one.- As a special case, if the field exists but its value is empty, place T at the very end of the list. [incorrect: this step comes earlier, taking precedence over a
list-beforefield with a value]
- As a special case, if the field exists but its value is empty, place T at the very end of the list. [incorrect: this step comes earlier, taking precedence over a
If any tiddlers still remain, place them at the end of the list in ascending alphabetical order of title. The difference between capital and lowercase letters is ignored. [describes the actual effect, but is misleading and IMO makes it harder to understand the preceding parts of the algorithm: this happened between steps 1 and 2]
I should note that the current documentation also doesn't describe the recursive behavior at all, which I think could lead you to believe it would do something quite different than what it actually does.
To Reproduce You can test the behavior on https://tiddlywiki.com, and see that it matches the behavior described by the code, and not that described by the documentation (duh, I guess).
Expected behavior
The documentation should accurately describe the behavior of a live wiki. A number of edge cases are currently described wrongly; most importantly (and this is not really an edge case), it currently sounds like list fields take precedence over list-before or list-after fields, when the reverse is true.
TiddlyWiki Configuration TiddlyWiki 5.4.1, live on https://tiddlywiki.com. Platform not relevant for this report.
Source: TiddlyWiki/TiddlyWiki5