putfirst and putlast

64 views
Skip to first unread message

Mohammad

unread,
Dec 27, 2019, 10:02:22 AM12/27/19
to TiddlyWiki
How putfirst and putlast work?

  • Assume you have a list in uu with value: aa bb cc dd ee
  • Then you want using a button move cc to first position or last position
  • how it can be done?

I used the below code it uses uu  as a tiddler with a list of above values but seems putlast does not work correctly!


\define mreorder()
<$tiddler tiddler={{{[[reorder]get[text]]}}}>
<span style="display:inline-block;min-width:120px;font-weight:700;"><$view tiddler=reorder field=text/></span>
<$button class="tc-btn-invisible">down
<$action-listops $tiddler="uu" $field="list" $subfilter="+[move<currentTiddler>]"/>
</$button>
&nbsp;
<$button class="tc-btn-invisible">up
<$action-listops $tiddler="uu" $field="list" $subfilter="+[move:-1<currentTiddler>]"/>
</$button>
&nbsp;
<$button class="tc-btn-invisible">putfirst
<$action-listops $tiddler="uu" $field="list" $subfilter="[<currentTiddler>]+[putfirst[]]"/>
</$button>
&nbsp;
<$button class="tc-btn-invisible">putlast
<$action-listops $tiddler="uu" $field="list" $subfilter="[<currentTiddler>]+[putlast[]]"/>
</$button>
</$tiddler>
\end


<<mreorder>>

<$list filter="[list[uu]]">
<$radio tiddler="reorder" field=text value=<<currentTiddler>>> <$view field=title/></$radio><br>
</$list>



Any suggestion?

--Mohammad

Thomas Elmiger

unread,
Dec 29, 2019, 4:30:57 AM12/29/19
to TiddlyWiki
Hi Mohammad,

According to the documentation putfirst and putlast move a number of items to *the other* end of the list. So in your case you would have to make complicated calculations... Maybe the naming evokes the impression that they move defined items to the beginning or the end of the list. But they do that only for items already at an end of the list, not for any item.

My advice would be to make three steps. First store cc in a variable. Then remove it from the list. Then append or prepend to the list.

All the best,
Thomas

Mohammad

unread,
Dec 29, 2019, 4:45:26 AM12/29/19
to TiddlyWiki
Hi Thomas,
 Thank you for your note!
Documentation is not clear and hopefully Jeremy add some examples!
Yes, this is a good trick! lets try it.

Cheers
Mohammad


 

All the best,
Thomas

Thomas Elmiger

unread,
Dec 29, 2019, 4:51:21 AM12/29/19
to TiddlyWiki
If you follow the links in the docs you should find examples like https://tiddlywiki.com/#putfirst%20Operator%20(Examples)

Mohammad

unread,
Dec 29, 2019, 4:55:36 AM12/29/19
to TiddlyWiki
Thanks Thomas!
Reply all
Reply to author
Forward
0 new messages