Multiple suspendHistory & undo problem [solved]

Discussion of the xtools Toolkit

Moderators: Tom, Kukurykus

SzopeN

Multiple suspendHistory & undo problem [solved]

Post by SzopeN »

I've observed following strange behavior on CS3 and CS4 when using subsequent calls to suspendHistory

Code: Select allfunction foo() {
   // Each line produces 2 history entries: 'New Layer' and 'Layer Properties'
   doc.artLayers.add().name = 'fooA';
   doc.artLayers.add().name = 'fooB';
   doc.artLayers.add().name = 'fooC';
}

function bar() {
   doc.artLayers.add().name = 'barA';
   doc.artLayers.add().name = 'barB';
   doc.artLayers.add().name = 'barC';
}

function go() {
   doc.suspendHistory('Function foo', 'foo()');
   doc.suspendHistory('Function bar', 'bar()');
}

function go2() {
   doc.suspendHistory('Function foo', 'foo()');
   activeDocument = activeDocument; // NOP
   doc.suspendHistory('Function bar', 'bar()');
   activeDocument = activeDocument; // NOP
}

app.documents.add();
var doc = app.activeDocument;
go();
executeAction( charIDToTypeID( "undo" ), undefined, DialogModes.NO );
$.writeln(doc.activeHistoryState.name); // writes "New" (!)

go2();
executeAction( charIDToTypeID( "undo" ), undefined, DialogModes.NO );
$.writeln(doc.activeHistoryState.name); // writes "Function foo"

foo();
executeAction( charIDToTypeID( "undo" ), undefined, DialogModes.NO );
$.writeln(doc.activeHistoryState.name); // writes "New Layer"


I think, go2's behavior is the expected one, because when 'undo' is invoked, only the last one history step is undone.

Code: Select all// Makes separate suspendHistory entries undoable (^Z)
Stdlib.suspendHistory( doc, name, fctn ) {
   doc.suspendHistory(name, fctn);
   activeDocument = activeDocument; // NOP
}
xbytor

Multiple suspendHistory & undo problem [solved]

Post by xbytor »

Added to stdlib.js.

Thanks,
-X