EvidentlyCube / TW5-AutoComplete

A TW5 plugin that enables completing Tiddler names in various text inputs.
MIT License
5 stars 1 forks source link

[Idea] Use $transclude instead of $text in Autocomplete Window #5

Open kookma opened 1 year ago

kookma commented 1 year ago

In https://evidentlycube.github.io/TW5-PluginShowcase/#%24%3A%2Fplugins%2FEvidentlyCube%2FAutoComplete%2Fwindow it shows the list of items using $text see the code:

    <$list
        filter="[list[$:/temp/AutoComplete/completion-data]rest<offset>first<limit>]"
        counter="index"
        emptyMessage="""<li class="label">No results</li>"""
    >
        <$list filter="[<index>add<offset>match<selected>]" variable="_" emptyMessage="""
            <li class="ec_ac-link" data-value=<<currentTiddler>>>
                <$text text={{{ [<currentTiddler>subfilter{$:/temp/AutoComplete/completion-data!!display-filter}] }}} />
            </li>
        """>
            <li class="ec_ac-link selected" data-value=<<currentTiddler>>>
                <$text text={{{ [<currentTiddler>subfilter{$:/temp/AutoComplete/completion-data!!display-filter}] }}} />
            </li>
        </$list>
    </$list>

This can replace the $text with $transclude as below to be able to handle Text References

    <$list
        filter="[list[$:/temp/AutoComplete/completion-data]rest<offset>first<limit>]"
        counter="index"
        emptyMessage="""<li class="label">No results</li>"""
    >
        <$list filter="[<index>add<offset>match<selected>]" variable="_" emptyMessage="""
            <li class="ec_ac-link" data-value=<<currentTiddler>>>
                <$transclude tiddler={{{ [<currentTiddler>subfilter{$:/temp/AutoComplete/completion-data!!display-filter}] }}} field="title"/>
            </li>
        """>
            <li class="ec_ac-link selected" data-value=<<currentTiddler>>>
                <$transclude tiddler={{{ [<currentTiddler>subfilter{$:/temp/AutoComplete/completion-data!!display-filter}] }}} field="title"/>
            </li>
        </$list>
    </$list>

As an example, see https://talk.tiddlywiki.org/t/auto-complete-plugin-1-0-14-complete-tiddlers-fields-and-your-dreams/5281/66 and the filter I have used for Display filter, still the Tiddlers in storyRiver excluding, <$text text="$:/AdvancedSearch"/> does not work (see description of https://tiddlywiki.com/#%24%3A%2Fcore%2FFilters%2FStoryList)

kookma commented 1 year ago

You may need also to revise the Test the filter in tiddlers tagged qith $:/tags/EC/AutoComplete/Trigger I assume you have used a template.

EvidentlyCube commented 1 year ago

Good idea, I'll make sure to make it use transclude!

EvidentlyCube commented 1 year ago

I am not too fond of the "use a filter to generate wikitext" possible solution here, at some point in the nearish future I'll be adding new functionalities and one of the changes will be ability to chose between rendering via a transclude or via a filter... Or just make it to be a template and figure out how to make it backwards compatible.

kookma commented 1 year ago

Great to know you will add new functionality!

Just to be a clear here:

  1. For list item you have used $text to show the label or caption for that item 2.If you want to add a trigger to show Advanced Search Filters in any textbox, you use a Suggestion Filter: like [all[tiddlers+shadows]tag[$:/tags/Filter]!is[draft]search:title<query>]

see the complete example above (in https://talk.tiddlywiki.org/t/auto-complete-plugin-1-0-14-complete-tiddlers-fields-and-your-dreams/5281/66).

  1. Now let's test: If you type filter: to trigger autocomplete with Advanced Search Filters you will see an item like Tiddlers in storyRiver excluding, <$text text="$:/AdvancedSearch"/> that means the current code in https://evidentlycube.github.io/TW5-PluginShowcase/#%24%3A%2Fplugins%2FEvidentlyCube%2FAutoComplete%2Fwindow will not wikify the field (here description) and you see such labels.

If you use $transclude this issue will resolved.

Q1. Is this solution is backward compatible? yes Q2 Is there any side effect? Yes, transclude may create links from CamelCase words in label Q2.1. What is the solution for this side effect? Disable camelcase link locally

Using transclude also allow you to use fields for label where they have wikitext. This is important because when you work with Core or other plugins, you may encounter such situations.

By the way, this is only a suggestion, and the current release (1.0.15) is very powerful and I myself can live with current release. Take any part you find useful!

EvidentlyCube commented 1 year ago

Going from memory, I wanted to respond to you a month ago but got distracted and forgot

The reason I don't want to implement this change is because doing it this way would make it problematic to use characters [ and ] in the template, as in some (many?) cases it would just output filter error. Which is why I want a solution without such traps!

kookma commented 1 year ago

I did not understand what is problematic. The transclude allows you to be able to use wikitext. Thank you anyway, I can live with current configuration, so feel free to close this issue!

EvidentlyCube commented 1 year ago

Reinvestigated the issue and here is the problem I was talking about: image

Essentially these two things:

But I am now trying to understand why I chose this... weird way of doing this, instead of just, I dunno, transcluding a template or something. Once I get down to working on 2.0 I'll probably have to make it backwards incompatible to fix the weird decisions I made here 🤔

kookma commented 1 year ago

Essentially these two things:

  • Because I use subfilter

Yes, that is right. In other words the problem is not with $text or $transclude here! The problem is with filter transclusion you use. {{{ [subfilter<someinput>] }}}, here someinput shall be a filter expression (in doc it says a selection of titles) but your test 3 and test 4 above are not!

What I understand here is you are going to show a label in drop down menu which may be created dynamically. So it is just a label and no matter how you create it! By the way I did not go through your code to see what other uses the display-filter has.

Once I get down to working on 2.0

Good news! looking forward it.