Sprotty
Toggle Dark/Light/Auto modeToggle Dark/Light/Auto modeToggle Dark/Light/Auto modeBack to homepage

Class. Command Stack

modelFactory

protected modelFactory: IModelFactory

Defined in: packages/sprotty/src/base/commands/command-stack.ts:106


modelViewer?

protected optional modelViewer: IViewer

Defined in: packages/sprotty/src/base/commands/command-stack.ts:114


offStack

protected offStack: ICommand[] = []

Defined in: packages/sprotty/src/base/commands/command-stack.ts:138

System commands should be transparent to the user in undo/redo operations. When a system command is executed when the redo stack is not empty, it is pushed to offStack instead.

On redo, all commands form this stack are undone such that the redo operation gets the exact same model as when it was executed first.

On undo, all commands form this stack are undone as well as system ommands should be transparent to the user.


options

protected options: CommandStackOptions

Defined in: packages/sprotty/src/base/commands/command-stack.ts:110


popupModelViewer?

protected optional popupModelViewer: IViewer

Defined in: packages/sprotty/src/base/commands/command-stack.ts:116


redoStack

protected redoStack: ICommand[] = []

Defined in: packages/sprotty/src/base/commands/command-stack.ts:119


stoppableCommands

protected stoppableCommands: Map<string, IStoppableCommand>

Defined in: packages/sprotty/src/base/commands/command-stack.ts:124

Map which holds the last stoppable command for certain action kinds.


syncer

protected syncer: AnimationFrameSyncer

Defined in: packages/sprotty/src/base/commands/command-stack.ts:109


undoStack

protected undoStack: ICommand[] = []

Defined in: packages/sprotty/src/base/commands/command-stack.ts:118


viewerProvider

protected viewerProvider: IViewerProvider

Defined in: packages/sprotty/src/base/commands/command-stack.ts:107

Accessors

currentModel

Get Signature

get protected currentModel(): Promise<SModelRootImpl>

Defined in: packages/sprotty/src/base/commands/command-stack.ts:158

Returns

Promise<SModelRootImpl>

Methods

createContext()

protected createContext(currentModel): CommandExecutionContext

Defined in: packages/sprotty/src/base/commands/command-stack.ts:427

Assembles the context object that is passed to the commands execution method.

Parameters

currentModel

SModelRootImpl

Returns

CommandExecutionContext


execute()

execute(command): Promise<SModelRootImpl>

Defined in: packages/sprotty/src/base/commands/command-stack.ts:174

Executes the given command on the current model and returns a Promise for the new result.

Unless it is a special command, it is pushed to the undo stack such that it can be rolled back later and the redo stack is cleared.

Parameters

command

ICommand

Returns

Promise<SModelRootImpl>

Implementation of

ICommandStack.execute


executeAll()

executeAll(commands): Promise<SModelRootImpl>

Defined in: packages/sprotty/src/base/commands/command-stack.ts:164

Executes all of the given commands. As opposed to calling execute() multiple times, the Viewer is only updated once after the last command has been executed.

Parameters

commands

ICommand[]

Returns

Promise<SModelRootImpl>

Implementation of

ICommandStack.executeAll


handleCommand()

protected handleCommand(command, operation, beforeResolve): void

Defined in: packages/sprotty/src/base/commands/command-stack.ts:215

Chains the current promise with another Promise that performs the given operation on the given command.

Parameters

command

ICommand

operation

(context) => CommandReturn

beforeResolve

(command, context) => void

a function that is called directly before resolving the Promise to return the new model. Usually puts the command on the appropriate stack.

Returns

void


initialize()

protected initialize(): void

Defined in: packages/sprotty/src/base/commands/command-stack.ts:141

Returns

void


isBlockUndo()

protected isBlockUndo(command): boolean

Defined in: packages/sprotty/src/base/commands/command-stack.ts:446

Parameters

command

ICommand

Returns

boolean


isPushToOffStack()

protected isPushToOffStack(command): boolean

Defined in: packages/sprotty/src/base/commands/command-stack.ts:438

Parameters

command

ICommand

Returns

boolean


isPushToUndoStack()

protected isPushToUndoStack(command): boolean

Defined in: packages/sprotty/src/base/commands/command-stack.ts:442

Parameters

command

ICommand

Returns

boolean


mergeOrPush()

protected mergeOrPush(command, context): void

Defined in: packages/sprotty/src/base/commands/command-stack.ts:348

Handling of commands after their execution.

Hidden commands are not pushed to any stack.

System commands are pushed to the offStack when the redo stack is not empty, allowing to undo the before a redo to keep the chain of commands consistent.

Mergable commands are merged if possible.

Parameters

command

ICommand

context

CommandExecutionContext

Returns

void


pushToUndoStack()

protected pushToUndoStack(command): void

Defined in: packages/sprotty/src/base/commands/command-stack.ts:274

Parameters

command

ICommand

Returns

void


redo()

redo(): Promise<SModelRootImpl>

Defined in: packages/sprotty/src/base/commands/command-stack.ts:194

Takes the topmost command from the redo stack, redoes its changes and pushes it ot the undo stack. Returns a Promise for the changed model.

Returns

Promise<SModelRootImpl>

Implementation of

ICommandStack.redo


redoFollowingSystemCommands()

protected redoFollowingSystemCommands(): void

Defined in: packages/sprotty/src/base/commands/command-stack.ts:412

System commands should be transparent to the user, so this method is called from redo() to re-execute all system commands at the top of the redoStack.

Returns

void


thenUpdate()

protected thenUpdate(): Promise<SModelRootImpl>

Defined in: packages/sprotty/src/base/commands/command-stack.ts:284

Notifies the Viewer to render the new model and/or the new hidden model and returns a Promise for the new model.

Returns

Promise<SModelRootImpl>


undo()

undo(): Promise<SModelRootImpl>

Defined in: packages/sprotty/src/base/commands/command-stack.ts:180

Takes the topmost command from the undo stack, undoes its changes and pushes it ot the redo stack. Returns a Promise for the changed model.

Returns

Promise<SModelRootImpl>

Implementation of

ICommandStack.undo


undoOffStackSystemCommands()

protected undoOffStackSystemCommands(): void

Defined in: packages/sprotty/src/base/commands/command-stack.ts:381

Reverts all system commands on the offStack.

Returns

void


undoPreceedingSystemCommands()

protected undoPreceedingSystemCommands(): void

Defined in: packages/sprotty/src/base/commands/command-stack.ts:395

System commands should be transparent to the user, so this method is called from undo() to revert all system commands at the top of the undoStack.

Returns

void


update()

update(model, cause?): void

Defined in: packages/sprotty/src/base/commands/command-stack.ts:310

Notify the ModelViewer that the model has changed.

Parameters

model

SModelRootImpl

cause?

Action

Returns

void


updateHidden()

updateHidden(model, cause?): void

Defined in: packages/sprotty/src/base/commands/command-stack.ts:320

Notify the HiddenModelViewer that the hidden model has changed.

Parameters

model

SModelRootImpl

cause?

Action

Returns

void


updatePopup()

updatePopup(model, cause?): void

Defined in: packages/sprotty/src/base/commands/command-stack.ts:330

Notify the PopupModelViewer that the popup model has changed.

Parameters

model

SModelRootImpl

cause?

Action

Returns

void