Skip to content

Commit daecb68

Browse files
committed
fix(历史记录): 画布后退到第一步可被拖拽
1 parent 1d91ee5 commit daecb68

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

packages/core/plugin/HistoryPlugin.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @Author: 秦少卫
44
* @Date: 2023-06-20 13:06:31
55
* @LastEditors: 秦少卫
6-
* @LastEditTime: 2024-04-17 12:26:45
6+
* @LastEditTime: 2024-04-17 13:22:48
77
* @Description: 历史记录插件
88
*/
99
import { fabric } from 'fabric';
@@ -29,11 +29,12 @@ class HistoryPlugin {
2929
constructor(canvas: fabric.Canvas & extendCanvas, editor: IEditor) {
3030
this.canvas = canvas;
3131
this.editor = editor;
32-
this._init();
3332

3433
fabric.Canvas.prototype._historyNext = () => {
3534
return this.editor.getJson();
3635
};
36+
37+
this._init();
3738
}
3839

3940
_init() {
@@ -59,6 +60,12 @@ class HistoryPlugin {
5960
}
6061

6162
undo() {
63+
// fix 历史记录退回到第一步时,画布区域可被拖拽
64+
if (this.canvas.historyUndo.length === 1) {
65+
this.editor.clear();
66+
this.canvas.clearHistory();
67+
return;
68+
}
6269
this.canvas.undo();
6370
this.historyUpdate();
6471
}

typings/extends.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ declare namespace fabric {
55
wrapperEl: HTMLElement;
66
isDragging: boolean;
77
_currentTransform: unknown;
8+
extraProps: any;
89
clearHistory(): void;
910
_historyNext(): void;
11+
_historyInit(): void;
1012
_centerObject: (obj: fabric.Object, center: fabric.Point) => fabric.Canvas;
1113
_setupCurrentTransform(e: Event, target: fabric.Object, alreadySelected: boolean): void;
1214
}

0 commit comments

Comments
 (0)