11import AdvancedCanvasPlugin from "src/main"
2- import { BBox , Canvas , CanvasData , CanvasEdge , CanvasElement , CanvasNode , CanvasView } from "src/@types/Canvas"
2+ import { BBox , Canvas , CanvasData , CanvasEdge , CanvasEdgeData , CanvasElement , CanvasNode , CanvasNodeData , CanvasView } from "src/@types/Canvas"
33import { patchObjectInstance , patchObjectPrototype } from "src/utils/patch-helper"
44import { CanvasEvent } from "./events"
55import { WorkspaceLeaf } from "obsidian"
@@ -191,8 +191,8 @@ export default class CanvasPatcher {
191191 const that = this
192192
193193 patchObjectInstance ( this . plugin , node , {
194- setData : ( next : any ) => function ( ... args : any ) {
195- const result = next . call ( this , ... args )
194+ setData : ( next : any ) => function ( data : CanvasNodeData , addHistory ?: boolean ) {
195+ const result = next . call ( this , data )
196196
197197 if ( node . initialized && ! node . isDirty ) {
198198 node . isDirty = true
@@ -204,6 +204,9 @@ export default class CanvasPatcher {
204204 this . canvas . data = this . canvas . getData ( )
205205 this . canvas . view . requestSave ( )
206206
207+ // Add to the undo stack
208+ if ( addHistory ) this . canvas . pushHistory ( this . canvas . getData ( ) )
209+
207210 return result
208211 } ,
209212 getBBox : ( next : any ) => function ( ...args : any ) {
@@ -223,8 +226,8 @@ export default class CanvasPatcher {
223226 const that = this
224227
225228 patchObjectInstance ( this . plugin , edge , {
226- setData : ( next : any ) => function ( ... args : any ) {
227- const result = next . call ( this , ... args )
229+ setData : ( next : any ) => function ( data : CanvasEdgeData , addHistory ?: boolean ) {
230+ const result = next . call ( this , data )
228231
229232 if ( edge . initialized && ! edge . isDirty ) {
230233 edge . isDirty = true
@@ -236,6 +239,9 @@ export default class CanvasPatcher {
236239 this . canvas . data = this . canvas . getData ( )
237240 this . canvas . view . requestSave ( )
238241
242+ // Add to the undo stack
243+ if ( addHistory ) this . canvas . pushHistory ( this . canvas . getData ( ) )
244+
239245 return result
240246 } ,
241247 render : ( next : any ) => function ( ...args : any ) {
0 commit comments