Delete confirmation for blank tiddlers

76 views
Skip to first unread message

kebi

unread,
Aug 19, 2020, 8:00:46 PM8/19/20
to tiddl...@googlegroups.com
Hello guys,
by default if a tiddler contains some text in its body TiddlyWiki is gonna ask if you are sure about deleting the tiddler, but it won't ask anything if the body is empty.
How can I change the behavior so that TiddlyWiki always asks me if im sure about deleting a tiddler oven for blank ones??

Eric Shulman

unread,
Aug 19, 2020, 10:11:40 PM8/19/20
to TiddlyWiki
On Wednesday, August 19, 2020 at 5:00:46 PM UTC-7, kebi wrote:
by default if a tiddler contains some text in its body TiddlyWiki is gonna ask if you are sure about deleting the tiddler, but it won't ask anything if the body is empty.

That is not the experience I get when I try the following at tiddlywiki.com

2) press "+" button in the sidebar to start editing "Draft of New Tiddler"
3) press "checkmark" button in the tiddler toolbar to create "New Tiddler" (note that the body is empty)
4) press "pencil" button in the tiddler toolbar to edit "New Tiddler"
5) press "trashcan" button in the tiddler toolbar to delete "New Tiddler"

You are prompted to confirm the deletion.

Can you describe the exact step-by-step actions that produce the behavior you want to change?

-e

kebi

unread,
Aug 19, 2020, 10:22:07 PM8/19/20
to TiddlyWiki
Thanks Eric for your testing.
The delete button I'm talking about is not the one inside the edit tiddler view, but the one in the view toolbar ($:/core/ui/Buttons/delete)

- kebi

TW Tones

unread,
Aug 20, 2020, 1:42:25 AM8/20/20
to TiddlyWiki
Kebi,

I agree this is what happens if you create a tiddler, with only its title.
  • A Quick look at the delete tiddler button $:/core/ui/Buttons/delete shows it uses the button message="tm-delete-tiddler"
  • There is no mention of this behaviour and no parameters to override it.
  • Only changing the text stops this behaviour, adding a tag or field with a value does not cause the are you sure warning.
It can be quite common to create tiddlers accidentally and want to simply delete them, so I am not surprised at this behaviour. When it is only a tiddler with a title then all that is deleted is the title, if there is any content what so ever, you may not be able to see it eg; fields, then it should trigger the confirmation (in my view).

Perhaps you can submit and issue on github for a setting to be provided in the control panel settings to change this behaviour?

In the mean time perhaps you could consider either modifying the tiddler, even just add space to the text. Another way to do this is to make your own "new tiddler button" and modify it to set the text to " " space only, and hide the existing one. However new here and other will not be affected?

Good catch

Regards
Tones

Eric Shulman

unread,
Aug 20, 2020, 2:25:31 AM8/20/20
to tiddl...@googlegroups.com
On Wednesday, August 19, 2020 at 10:42:25 PM UTC-7, TW Tones wrote:
  • A Quick look at the delete tiddler button $:/core/ui/Buttons/delete shows it uses the button message="tm-delete-tiddler"
The processing for the tm-delete-tiddler message is defined here: $:/core/modules/widgets/navigator.js,
which sets up an event listener that triggers: handleDeleteTiddlerEvent

Examining this function, we find the following lines of code:

if((this.wiki.getTiddler(originalTitle) || (tiddler.fields.text || "") !== "")
 
&& !confirm($tw.language.getString("ConfirmDeleteTiddler",{variables:{title: confirmationTitle}}))) {
 
return false;
 
}

This code checks to see if getTiddler() returns a non-null value (i.e., the tiddler exists) or if the current text field is not blank (i.e., text has been entered while editing). If either of these conditions is true, then it prompts for confirmation.  If you press "cancel", then the code skips the delete action (return false).  If you press "ok", the code continues on to perform the deletion.

From the above, it appears that it *should* be asking to confirm since the tiddler does exist.
However, it seems that this is not what is actually happening.
I don't see where the logic is broken, but this is where it occurs.

-e

kebi

unread,
Aug 20, 2020, 8:15:09 AM8/20/20
to TiddlyWiki
Thanks Tony and Eric for your analyses, in $:/core/modules/widgets/navigator.js I tried removing the following condition
|| (tiddler.fields.text || "")

and now it always asks before deletion.
The code that I removed was an "or" condition so it should have worked without changing the code, that's strange.

- kebi

Eric Shulman

unread,
Aug 20, 2020, 9:50:30 AM8/20/20
to TiddlyWiki
On Thursday, August 20, 2020 at 5:15:09 AM UTC-7, kebi wrote:
Thanks Tony and Eric for your analyses, in $:/core/modules/widgets/navigator.js I tried removing the following condition
|| (tiddler.fields.text || "")
and now it always asks before deletion.

Hmm... I think that conditional is needed if you are creating a new tiddler and type something into the text field, and then press the delete button from the editor toolbar.  In that situation, the tiddler doesn't exist yet, but the tiddler.fields.text value is not blank, so it should ask before discarding the input.  I suggest checking the above interaction and see if it still asks.

In any case, modifying this central TWCore tiddler is ill-advised, since it can interfere with upgrading later on.  Reporting an issue on github is the right course of action, so Jeremy can take a look and possibly find a better fix.

-e


Reply all
Reply to author
Forward
0 new messages