Make TiddlyWiki ignore the dirty state

I want to make my wiki publicly available to my users (who know nothing about TW). There’re some operations that will turn TW into a “dirty state” (indicated by the red save button) Screenshot 2021-09-09 233133.

If the TW is in this state and the user tries to refresh or close the tab, they will see the warning window.
Screenshot 2021-09-09 233237

I dont want the users to panic and think they have done something wrong to the website. Is it possible to suppress this warning window? Or perhaps make the TW to ignore its dirty state?

Note: Most buttons will be hidden and they user won’t even see the red save button. But the popup will still show if they close the tab.

…make the TW to ignore its dirty state…

The $:/config/SaverFilter shadow tiddler contains a filter that defines which tiddlers determine when the file is marked as “dirty” (i.e., needing saving). Here’s the default contents of that tiddler:

[all[]] -[prefix[$:/HistoryList]] -[prefix[$:/StoryList]]
-[status[pending]plugin-type[import]] -[[$:/isEncrypted]] -[[$:/UploadName]]
-[prefix[$:/state/]] -[prefix[$:/temp/]]

If you clear the contents of this tiddler (or add a leading “-” so [all[]] becomes -[all[]]) and then save the file, when you reload it, it will no longer require saving, regardless of any tiddlers you may change.

Note that $:/config/SaverFilter does not determine which tiddlers are actually saved when you press the “save changes” button. The filter that determines what gets saved is defined in $:/core/save/all, which has this contents:

\import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]
\define saveTiddlerFilter()
[is[tiddler]] -[prefix[$:/state/popup/]] -[prefix[$:/temp/]] -[prefix[$:/HistoryList]]
-[status[pending]plugin-type[import]] -[[$:/boot/boot.css]]
-[type[application/javascript]library[yes]] -[[$:/boot/boot.js]]
-[[$:/boot/bootprefix.js]] +[sort[title]] $(publishFilter)$`
\end
{{$:/core/templates/tiddlywiki5.html}}

The saveTiddlerFilter() macro defines the list of tiddlers that will be saved. Take note of the last bit, where it says $(publishFilter)$. This allows you to easily modify the list of tiddlers without directly editing $:/core/save/all. Instead, define a separate macro named “publishFilter”, listing which tiddlers you do (or don’t) want saved.

For example, suppose you have a tiddler named “MyTempStuff” that you never want saved. To omit this tiddler from the save, just create a tiddler (e.g., “MyPublishFilter”), tagged with $:/tags/Macro, containing:

\define publishFilter() -[[MyTempStuff]]

From then on, “MyTempStuff” will not be saved with the rest of the file contents, and each time you save-and-reload, that tiddler will be automatically discarded.

Conversely, suppose you do want the $:/temp tiddlers to be saved. Then, you could write something like:

\define publishFilter() -[[MyTempStuff]] [prefix[$:/temp]]

which would reverse the effect of the default -[prefix[$:/temp] filter that exists in the $:/core/save/all shadow definition.

enjoy,
-e

5 Likes

Hi @EricShulman . As always, thank you for your informative response! If I understand correctly, the contents in $:/config/SaverFilter are what we need to modify to make TW ignore the changes to certain tiddler(s).

So if some operation changes the tiddler X and I dont want the save button to turn red because of this, then i simply add -[[X]] at the end of the contents in $:/config/SaverFilter right?

Actually to be more specific, I wanted to use the “Stories” plugin (for using two columns) found in Stroll in my public wiki. But I notice that if I divert a tiddler to the second column then the wiki is dirty. (Try diverting “Welcome to Stroll” to the second column to see what I mean).

Ideally, I want users to navigate tiddlers freely (including moving to second column) without dirtying the wiki. What tiddlers should I subtract from $:/config/SaverFilter?

Also, If I delete everything in $:/config/SaverFilter then it won’t affect the saving of my node.js version right? I mean I want everything to be saved as normal in node.js version but in a single html file it should not be dirty (easily).

When using the Local Storage plugin I have wanted to do something similar. What I do is hide the save changes button behind the more button and turn off automatic saving. The only time they will have to face the fact they have changes is when leaving the page.

Of course if the local storage is working correctly they will not loose content.

Separately for read only (for me) wikis such as tiddlywiki.com I have a bookmarklet that clears the dirty state when I click it. This clears the dirty flag.

javascript:(function(){ $tw.saverHandler.numChanges = 0; $tw.saverHandler.updateDirtyStatus(); })();

I would like to see the above bookmarklet translated into a macro or action we can initiate from inside tiddly wiki. Then this discussions original requirement could be addressed, and if I build a mechanism to export changes (not save the wiki) I could also reset the dirty state.

Hi @TW_Tones . While searching for solutions I come across this wiki where he made a custom save button that invokes tm-save-wiki with custom publishFilter. (Check the contents of the linked tiddlers.) You can also set fields of some tiddlers when the the button is pressed as well. This way you can make a sub/custom wiki from within the main wiki.

As for my own question, I found a way to avoid dirty state when using Stories plugin.

  • Open the tiddler $:/config/SaverFilter
  • Append its contents with -[[$:/config/_sq/Stories/story2]] -[[$:/_sq/Stories/Story2StoryList]] -[[$:/_sq/Stories/Story2HistoryList]]
    After you save the wiki to a single .html file and open it, the wiki won’t be dirtied anymore when you use the second column :slight_smile:
1 Like

Hi, just enable this plugin when publishing your website Prevent Edit plugin for plugin developers

(you can enable it by default, or +this plugin before you making the HTML in your build script)

1 Like

@Pak, great question!

@EricShulman, very enlightening answer!

FWIW, I do have wiki that I put online which should not be saveable and shouldn’t freak-out the user with any message asking about leaving (i.e. “dirty detection”).

I am going to see if I can apply Eric’s solution inside StartupActions that detect when the wiki is online. This would allows me to edit and maintain it offline in full capability–knowing that when put online its only showing what the user needs to see and without any scary messages ever.

Just a comment
TT

1 Like

I read the title of this thread, and thought, No, Alabama has a right to use TiddlyWiki, too. :slight_smile:

1 Like