瀏覽代碼

fix: do not push history stack when persisted is the same with peek

Peng Xiao 3 年之前
父節點
當前提交
dd605a45f3

+ 1 - 0
tldraw/apps/tldraw-logseq/src/lib/shapes/LogseqPortalShape.tsx

@@ -212,6 +212,7 @@ export class LogseqPortalShape extends TLBoxShape<LogseqPortalShapeProps> {
 
     const onPageNameChanged = React.useCallback((id: string) => {
       transaction(() => {
+        app.history.resume()
         this.update({
           pageId: id,
           size: [600, 320],

+ 5 - 1
tldraw/packages/core/src/lib/TLHistory.ts

@@ -1,5 +1,6 @@
 import { TLApp, TLPage, TLDocumentModel, TLShape } from '~lib'
 import type { TLEventMap } from '~types'
+import { deepEqual } from '~utils'
 
 export class TLHistory<S extends TLShape = TLShape, K extends TLEventMap = TLEventMap> {
   constructor(app: TLApp<S, K>) {
@@ -12,7 +13,7 @@ export class TLHistory<S extends TLShape = TLShape, K extends TLEventMap = TLEve
   isPaused = true
 
   get creating() {
-    return this.app.selectedTool.currentState.id === 'creating';
+    return this.app.selectedTool.currentState.id === 'creating'
   }
 
   pause = () => {
@@ -38,6 +39,9 @@ export class TLHistory<S extends TLShape = TLShape, K extends TLEventMap = TLEve
 
     const { serialized } = this.app
 
+    // Do not persist if the serialized state is the same as the last one
+    if (deepEqual(this.stack[this.pointer], serialized)) return
+
     if (this.pointer < this.stack.length) {
       this.stack = this.stack.slice(0, this.pointer + 1)
     }

+ 1 - 0
tldraw/packages/core/src/lib/TLPage/TLPage.ts

@@ -280,6 +280,7 @@ export class TLPage<S extends TLShape = TLShape, E extends TLEventMap = TLEventM
 
     if (!deepEqual(updated, curr) || shapesToDelete.length) {
       transaction(() => {
+        this.app.history.resume()
         this.update({
           bindings: updated.bindings,
         })

+ 1 - 0
tldraw/packages/core/src/lib/tools/TLSelectTool/states/PointingCanvasState.ts

@@ -53,6 +53,7 @@ export class PointingCanvasState<
           point: [...this.app.inputs.originPoint],
         })
         shape.setDraft(true)
+        this.app.history.pause()
         this.app.setActivatedShapes([shape.id])
         this.app.currentPage.addShapes(shape)
       }