extending undo...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-02-09 17:09:53 +03:00
parent b4eb5e3101
commit 06d60a9109

View File

@ -2087,7 +2087,7 @@ var JournalActions = actions.Actions({
[e.action].apply(that, e.args) }) }], [e.action].apply(that, e.args) }) }],
// XXX would be a good idea to add arguments this this: // XXX would be a good idea to add arguments this this:
// <count> - number of actions to undo // <count> - number of actions to undo (DONE)
// 'unsaved' - all actions till last save marker // 'unsaved' - all actions till last save marker
// XXX needs very careful revision... // XXX needs very careful revision...
// - should this be thread safe??? (likely not) // - should this be thread safe??? (likely not)
@ -2098,6 +2098,7 @@ var JournalActions = actions.Actions({
// XXX should we run undo of every action that supports it in the chain??? // XXX should we run undo of every action that supports it in the chain???
// ...i.e. multiple extending actions can support undo // ...i.e. multiple extending actions can support undo
// XXX will also need to handle other methods + aliases in chain... // XXX will also need to handle other methods + aliases in chain...
// XXX EXPERIMENTAL...
undo: ['Edit/Undo', undo: ['Edit/Undo',
doc`Undo last action from .journal that can be undone doc`Undo last action from .journal that can be undone
@ -2112,49 +2113,53 @@ var JournalActions = actions.Actions({
`, `,
{mode: function(){ {mode: function(){
return (this.journal && this.journal.length > 0) || 'disabled' }}, return (this.journal && this.journal.length > 0) || 'disabled' }},
function(){ function(count=1){
var journal = this.journal.slice() || [] var journal = this.journal.slice() || []
var rjournal =
this.rjournal =
(this.hasOwnProperty('rjournal') || this.rjournal) ?
this.rjournal || []
: []
var rjournal = this.rjournal = // XXX add test for save point...
(this.hasOwnProperty('rjournal') || this.rjournal) ? // XXX this counts undoable actions only -- is this correct...
this.rjournal || [] while(count-- > 0
: [] && journal.length > 1){
for(var i = journal.length-1; i >= 0; i--){
var a = journal[i]
for(var i = journal.length-1; i >= 0; i--){ // see if the action has an explicit undo attr...
var a = journal[i] var undo = this.getActionAttr(a.action, 'undo')
// see if the action has an explicit undo attr... // general undo...
var undo = this.getActionAttr(a.action, 'undo') if(undo){
// restore focus to where it was when the action
// was called...
this.focusImage(a.current)
// general undo... // call the undo method/action...
if(undo){ // NOTE: this is likely to have side-effect on the
// restore focus to where it was when the action // journal and maybe even rjournal...
// was called... // NOTE: these side-effects are cleaned out later.
this.focusImage(a.current) var undo = undo instanceof Function ?
// pass the action name...
undo.call(this, a)
: typeof(undo) == typeof('str') ?
// XXX pass journal structure as-is... (???)
this[undo].apply(this, a.args)
: null
// call the undo method/action... // push the undone command to the reverse journal...
// NOTE: this is likely to have side-effect on the rjournal.push(journal.splice(i, 1)[0])
// journal and maybe even rjournal...
// NOTE: these side-effects are cleaned out later.
var undo = undo instanceof Function ?
// pass the action name...
undo.call(this, a)
: typeof(undo) == typeof('str') ?
// XXX pass journal structure as-is... (???)
this[undo].apply(this, a.args)
: null
// push the undone command to the reverse journal... // restore journal state...
rjournal.push(journal.splice(i, 1)[0]) // NOTE: calling the undo action would have cleared
// the rjournal and added stuff to the journal
// so we will need to restore things...
this.journal = journal
this.rjournal = rjournal
// restore journal state... break } } } }],
// NOTE: calling the undo action would have cleared
// the rjournal and added stuff to the journal
// so we will need to restore things...
this.journal = journal
this.rjournal = rjournal
break } } }],
redo: ['Edit/Redo', redo: ['Edit/Redo',
doc`Redo an action from .rjournal doc`Redo an action from .rjournal