Skip to content

Commit

Permalink
Merge pull request #15766 from BabylonJS/undo-redo-ignore
Browse files Browse the repository at this point in the history
Allow user to disable undo/redo for NGE
  • Loading branch information
sebavan authored Nov 4, 2024
2 parents a9fb65c + 9ed318c commit c267a4a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
11 changes: 10 additions & 1 deletion packages/dev/sharedUiComponents/src/historyStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export class HistoryStack implements IDisposable {
private _dataProvider: () => any;
private _applyUpdate: (data: any) => void;

/**
* Gets or sets a boolean indicating if the stack is enabled
*/
public isEnabled = true;

/**
* Constructor
* @param dataProvider defines the data provider function
Expand All @@ -28,6 +33,10 @@ export class HistoryStack implements IDisposable {
* @returns true if the event was processed
*/
processKeyEvent(evt: KeyboardEvent): boolean {
if (!this.isEnabled) {
return false;
}

if (evt.ctrlKey || evt.metaKey) {
if (evt.key === "z" || evt.key === "Z") {
if (evt.shiftKey) {
Expand Down Expand Up @@ -171,7 +180,7 @@ export class HistoryStack implements IDisposable {
* Stores the current state
*/
public store() {
if (this._locked) {
if (this._locked || !this.isEnabled) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,14 @@ export class PropertyTabComponent extends React.Component<IPropertyTabComponentP
this.props.globalState.stateManager.onGridSizeChanged.notifyObservers();
}}
/>
<CheckBoxLineComponent
label="Undo / Redo"
isSelected={() => DataStorage.ReadBoolean("UndoRedo", true)}
onSelect={(value: boolean) => {
DataStorage.WriteBoolean("UndoRedo", value);
this.props.globalState.stateManager.historyStack.isEnabled = value;
}}
/>
<TextInputLineComponent
label="Node Material ID"
value={DataStorage.ReadString("NMEID", "")}
Expand Down
1 change: 0 additions & 1 deletion packages/tools/nodeGeometryEditor/src/globalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export class GlobalState {
this.stateManager = new StateManager();
this.stateManager.data = this;
this.stateManager.lockObject = this.lockObject;

RegisterElbowSupport(this.stateManager);
RegisterDebugSupport(this.stateManager);
RegisterNodePortDesign(this.stateManager);
Expand Down
1 change: 1 addition & 0 deletions packages/tools/nodeGeometryEditor/src/graphEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export class GraphEditor extends React.Component<IGraphEditorProps, IGraphEditor

// Create the stack
this._historyStack = new HistoryStack(dataProvider, applyUpdate);
this._historyStack.isEnabled = DataStorage.ReadBoolean("UndoRedo", true);
globalState.stateManager.historyStack = this._historyStack;

// Connect to relevant events
Expand Down

0 comments on commit c267a4a

Please sign in to comment.