Jermolene/TiddlyWiki5 — pull request #497 by buggyj (2014-03-20 05:05:44+00:00)
Title: 'Draft of' tiddler appears after tiddler is saved

'Draft of' tiddler appears after tiddler is saved
To reproduce the problem:
With a v508 TW5, created a new tiddler with a lot of text, maybe more than 100 lines. Save and re-edit. click on the text, press ctrl and return (saves the tiddler) then type a character.
see in the 'recent' sidebar tab that the 'Draft of' tiddler exists.

Explaination:
While the user is editing a tiddler, a number of edit-saves can occur at times e1, e2,... en. A user-save will happen at some time u1. the events that give rise to e1...en will be different events (eg, key events timers, etc) to the event that generates the user-save (mouse click), so there is no guarantee to the ordering of the events en and u1, and it is possible that the u1 will have between en-1 and en. This case leads to the edit-save occurring after the deletion of the 'Draft of ' tiddler (caused by user-save) and will cause the 'Draft of' tiddler to be recreated.

Proposed Solution:
The base widget has been modified to include a save(deleting) and saveChildren(deleting) methods, and thus these appear in all widgets.
The save() method calls saveChildren(), which propagates save() down the tree. The Edit-text widget responds to save(deleting) by saving any outstanding edits and sets a deleted flag that is always checked, so that subsequent events are ignored. [the deleting parameter tells the edit-text widget to set its deleted flag, otherwise it just saves outstanding edits].

A save widget has been created to initiate the above process. It has a listener for the "tw-save-tiddler" event, and calls saveChildren(true).
The save widget must be a parent of the save button and the edit widget, and so is placed in the EditTemplate
The save widget also debounce the "tw-save-tiddler" (only calls the save() method once.)