[tw5] Adding duplicate title in title list

Ok, so I have the following list:

foo foo foo bar

I then want to append ‘foo’ to the end of that list such that I wind up with:

foo foo foo bar foo

So I try the following filter:

[[foo foo foo bar]enlist-input:raw[]] [[foo]]

That results in:

foo foo bar foo

This is unexpected to me, which means that there is something I don’t understand.

So I have two questions:

  1. Why is the title not appended as I expected?
  2. How can I get the result I want? To add complexity (cause why not?), the list will be generated dynamically based on user input, titles will only sometimes be of existing tiddlers, and the titles can have spaces xD.

I should add that the list is currently stored as a field, so my filter is more along the lines of

[all[current]get[fieldName]enlist-input:raw[]] []

I couldn’t use the listops action widget subfilters because they automatically dedup so I need to use the full filter which doesn’t fully dedup my list but, at least with this filter, still makes me lose entries.

Answer to question #1:

By default, titles resulting from a filter are only listed once, with the last instance of a given title “dominantly appended” to the list (i.e., duplicates are removed). Thus, in your example, adding [[foo]] to the end of the list automatically removed the first instance of foo from the front of the list. You’ve already discovered the use of the :raw suffix for the enlist-input operator, which prevents duplicates from being removed when you enlist an existing space-separated list. Another bit of filter syntax that helps with preserving duplicates is the “=” prefix on a filter run. To get the results you expected, you would write: [[foo foo foo bar]enlist-input:raw[]] =[[foo]].

Answer to question #2:

As you noted in your followup message, you have an existing list stored in a tiddler field called fieldName. Let’s assume this field contains 4 items: foo [[bar baz]] mumble [[frotz gronk snork]] (where the 2nd and 4th items contain spaces). To add an item to that list, you would write something like this:: [<currentTiddler>get[fieldName]enlist-input:raw[]] =[<addedTitle>]. Note also that using <currentTiddler> in your filter is slightly more efficient than all[current], since the all[] operator first needs to parse the operand (current) to determine that you want to retrieve the current tiddler’s title, while <currentTiddler> directly retrieves the title without the added internal layer of parsing.

enjoy,
-e

Amazing response, Eric. Thank you!

That worked perfectly! I need to spend some quality time with https://tiddlywiki.com/#Filter%20Expression. There is a lot of new stuff on there I hadn’t seen before!

Note also that using <currentTiddler> in your filter is slightly more efficient than all[current]
See, I used to use currentTiddler but saw so many examples with all[current] that I assumed that there was some optimization going on there. Noted and adjusted. Great tip!

enjoy
I will, thank you!