Another set of eyes on my code

144 views
Skip to first unread message

TW Tones

unread,
Jul 26, 2021, 8:49:29 AM7/26/21
to TiddlyWiki
Folks,

Deep within a larger project I have some macros. there is a button that displays its tooltip but its actions are not occurring. I have spent hours trying work out why it is not working when it did previously.

Can anyone see why the first button is visible but not reacting, if it did I would then see the second button. Any suggestions would be helpful.

\define field-state-update() $:/state/$(fieldname)$-update
\define tiddler-field-value-temp() $:/temp/$(currentTiddler)$/$(fieldname)$-update
\define field.update() 
<$list filter="[<field-state-update>!has[title]]" variable=nul>
   <$transclude tiddler=<<field-type-tiddler>> field="field-view"/> 
   <$button class="tc-btn-invisible" tooltip="click to edit $(fieldname)$">
        <$action-createtiddler $basetitle=<<field-state-update>> text="existence toggled in field.update macro"/>
        <$action-createtiddler $basetitle=<<tiddler-field-value-temp>> text=<<field.value>>/>
        {{$:/PSaT/fancy-fields/icons/edit-field}}
   </$button>
</$list>
<$list filter="[<field-state-update>has[title]]" variable=nul>
   <$transclude tiddler=<<field-type-tiddler>> field="field-edit"/> 
   <$button message="tm-delete-tiddler" param=<<field-state-update>> class="tc-btn-invisible" tooltip="finish update of $(fieldname)$">
       {{$:/PSaT/fancy-fields/icons/edit-field}}
   </$button>
   <$button class="tc-btn-invisible" tooltip="Restore $(fieldname)$">
       <$action-setfield $tiddler=<<currentTiddler>> $field=<<fieldname>> $value=<$transclude tiddler=<<tiddler-field-value-temp>>/> />
       {{$:/PSaT/fancy-fields/icons/restore-field}}
   </$button>
</$list>
\end

More info

I invoke this with <<field.update>>  and fieldname field-type-tiddler is already set. The green filter never comes true, also proving <<field-state-update>> is never created.
<$action-createtiddler $basetitle=<<field-state-update>> text="existence toggled in field.update macro"/>
<$action-createtiddler $basetitle=<<tiddler-field-value-temp>> text=<<field.value>>/>
So the above actions do not occur.

These lines in the above work on their own
   <$transclude tiddler=<<field-type-tiddler>> field="field-edit"/> 
   <$transclude tiddler=<<field-type-tiddler>> field="field-view"/> 

Thanks
Tones

PMario

unread,
Jul 26, 2021, 12:30:14 PM7/26/21
to TiddlyWiki
Hi Tony,
I would have a look at it, if you'd provide a json with 2 or 3 tiddlers in it that I can import at tiddlywiki.com, which show the problem.
Just with this code and the description, that I don't understand 100% it's hard to see a problem.
I'm not in the mood to create a testcase, that I have to guess by myself.
-mario

Charlie Veniot

unread,
Jul 26, 2021, 4:32:05 PM7/26/21
to TiddlyWiki
Silly thought: any chance you were doing some copy/pasting in the whereabouts of that button or the macros above ?

Just a couple of times, I've had situations in which it felt like I had hidden characters either at the end of a line or the beginning of the next line.

Strange problems fixed by going to the start of text on a line, and backspacing until the line is at the end of the preceding line, then separating those two lines all over again with a carriage return.

Kind of a goofy thing to try, but at least it doesn't take long.

Mark S.

unread,
Jul 26, 2021, 11:31:55 PM7/26/21
to TiddlyWiki
Unless something has changed in the rules of TW, you can't insert the contents of a widget in the middle of a widget this way:

<$action-setfield $tiddler=<<currentTiddler>> $field=<<fieldname>> $value=<$transclude tiddler=<<tiddler-field-value-temp>>/> />

This does seem like a possible copy/paste error per cj's suggestion.

TW Tones

unread,
Jul 27, 2021, 7:23:10 AM7/27/21
to TiddlyWiki
Thanks all,

Mario, I would share an example, but it is hard to extract a test case because as I said "Deep within a larger project", I will see what I can do if I get nowhere soon. 
  • Although when I extracted these macros from the others in an attempt it started working.
Charlie, I always cut and past but usually only from my own working code. but I did remove some white space, thanks.
Mark, I think that was an issue either not yet discovered as it would not have being displayed however I corrected that to  $value={{{ [<tiddler-field-value-temp>get[text]] }}} 

I will keep reviewing thanks all.

Tones

Charlie Veniot

unread,
Jul 27, 2021, 8:35:37 AM7/27/21
to TiddlyWiki
The copy/paste deal that introduced a hidden character, backspacing fixing the problem:  it was code copied and pasted within my own tiddlers:  from tiddler "A Backup" to tiddler "A".

Just saying, no harm in quick-sanity-check backspacing a line to the previous one and slapping in a fresh carriage-return-line-feed-end-o'line characters.

Mark S.

unread,
Jul 27, 2021, 9:24:02 AM7/27/21
to TiddlyWiki
The thing is, I do see the second buttons after running the first button. So maybe I don't understand what you expect the code to do.

I do change " {{$:/PSaT/fancy-fields/icons/edit-field}}" to "MY BUTTON" because I don't want to go spelunking all over the TW world to find the particular icon you're using. However, if you have instance where you forgot to install the icon, that would explain why the button appears to not be working.

TW Tones

unread,
Jul 27, 2021, 6:08:35 PM7/27/21
to TiddlyWiki
Mark,

Thanks, when I separate the code it also works. Just knowing your success is important information. My suspicion is perhaps that one of the variables I make use of is misbehaving and causing the code to be misread. I am loath to wikify every variable just before use but I may need to do this to see if I can identify the offending piece.

I must say it can get difficult debugging larger solutions when we have multiple layers of macros and transclusions. The cognitive overload is high because so much is hidden within layers.

Thanks for your help
Tones

PMario

unread,
Jul 28, 2021, 3:41:23 AM7/28/21
to TiddlyWiki
Hi,
-m
Reply all
Reply to author
Forward
0 new messages