Skip to content

Behavior Change of clearStack #210

@rainerhahnekamp

Description

@rainerhahnekamp

Context

In withUndoRedo, the clearStack() method currently behaves as a hard reset: After calling it, the current state is removed from history, and the first change afterwards is treated as a brand-new initial state. This means canUndo() will be false after that first change, and only the second change becomes undoable.

This behavior came up in PR #207 and in the related discussion with @GregOnNet, @richardliebmann, and @jdegand.

Problem

During initialization, the stack always stores an initial state, so previous is never null.

When I want to clear the stack because of context switching - for example, moving from one file to another in an editor - the new context also has an initial state. In the current implementation, if I clear the stack after switching, the first change is seen as the initial one. Before the first change happens, the initiale state is null, which is not true.

Example of current behavior:

store.selectNewFile('graz.jpg'); 
// Store now has initial Graz state

store.clearStack(); 
// Graz state removed from history

store.setTitle('Wien'); 
// First change after clear: cannot undo back to Graz

store.undo(); 
// No effect, because Graz state wasn’t kept as baseline

Proposed Change

Change clearStack():

  • Clear the history.
  • Keep the current state as the new baseline (initial state).
  • The next change is undoable back to that baseline.

Proposed soft reset behavior:

store.selectNewFile('graz.jpg'); 
// Graz state is initial

store.clearStack(); 
// Graz state becomes new baseline

store.setTitle('Wien'); 
// First change is undoable back to Graz

store.undo(); 
// Restores Graz baseline

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions