making undo/redo more consistent (not done yet)

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-02-18 01:27:41 +03:00
parent 4c8ce37618
commit 03abe6c011

View File

@ -2009,16 +2009,10 @@ var JournalActions = actions.Actions({
target: undefined, target: undefined,
} }
// helper: get action method handling aliases...
var _getActionMethod = function(action, attr){
var meth = that.getActionAttr(action, attr)
while(typeof(meth) == typeof('str')){
meth = that.getActionAttr(meth, attr) }
return meth }
// test if we need to journal this action signature... // test if we need to journal this action signature...
var test = _getActionMethod(action, 'undoable') var test = that.getActionAttrAliased(action, 'undoable')
if(test && !test.call(that, data)){ if(test === false
|| (test && !test.call(that, data))){
return } return }
// journal after the action is done... // journal after the action is done...
@ -2026,7 +2020,7 @@ var JournalActions = actions.Actions({
data.target = this.current data.target = this.current
// prep to get additional undo state... // prep to get additional undo state...
// XXX this should be called for all actions in chain... // XXX this should be called for all actions in chain...
var update = _getActionMethod(action, 'getUndoState') var update = that.getActionAttrAliased(action, 'getUndoState')
update update
&& update instanceof Function && update instanceof Function
&& update.call(that, data) && update.call(that, data)
@ -2097,6 +2091,9 @@ var JournalActions = actions.Actions({
// ...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 in mode method count the undoable actions... // XXX in mode method count the undoable actions...
// XXX should we stop at non-undoable actions???
// ...intuitively, yes, as undoing past these may result in an
// inconsistent state...
// XXX EXPERIMENTAL... // XXX EXPERIMENTAL...
undo: ['Edit/Undo', undo: ['Edit/Undo',
doc`Undo last action(s) from .journal that can be undone doc`Undo last action(s) from .journal that can be undone
@ -2138,6 +2135,12 @@ var JournalActions = actions.Actions({
// XXX not sure if this is correct.... // XXX not sure if this is correct....
if(a.action == 'load'){ if(a.action == 'load'){
break } break }
// stop at explicitly undoable actions...
var undoable = this.getActionAttrAliased(a.action, 'undoable')
if(undoable === false
|| (undoable
&& !undoable.call(this, a))){
break }
// see if the action has an explicit undo attr... // see if the action has an explicit undo attr...
var undo = this.getActionAttr(a.action, 'undo') var undo = this.getActionAttr(a.action, 'undo')