Skip to content

Commit a968260

Browse files
committed
fix: confirm the firstState for the undoRedoPlugin
1 parent 5ace866 commit a968260

File tree

1 file changed

+16
-3
lines changed
  • front-end/h5/src/store/plugins/undo-redo

1 file changed

+16
-3
lines changed

front-end/h5/src/store/plugins/undo-redo/index.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,27 @@ import undoRedoHistory from './History'
88
// const unRecordHistoryMutationTypes = ['editor/setElementCommonStyle']
99
const recordHistoryMutationTypes = [
1010
'editor/recordRect',
11-
'editor/elementManager'
11+
'editor/elementManager',
12+
'editor/setEditingPage' // 用作 firstState,类似打开文件编辑之前的原始文件
1213
]
1314

1415
const undoRedoPlugin = (store) => {
1516
// initialize and save the starting stage
1617
undoRedoHistory.init(store)
17-
let firstState = cloneDeep(store.state)
18-
undoRedoHistory.addState(firstState)
18+
/**
19+
*
20+
* 注释addState(firstState) 代码
21+
* 因为 firstState 如果不注释则是整个editor的状态,而非作品的初始状态
22+
* 作品的初始状态<editor/setEditingPage>,也就是页面有内容最开始有内容时候的状态,注意不是setWork<此时editingPage 仍然为空,也不是 setEditingElement 因为用户可能不操作,直接从左侧列表选择组件,加到画布中>)
23+
* 如果添加到到history中,会导致history 变为:[editorState, workState1, workState2]
24+
* 这样执行 ctrl+z 的时候,会导致撤销的到最后一个时候(canUndo-> currentIndex > 0)
25+
* 其实是 editorState,导致画布区域显示空白(因为那时候 editorState 中的 work 为null,并没有加载work)
26+
* 为何 canUndo = currentIndex>0,因为 currentIndex = 0 的时候,说明 history 数组中只有一个状态了,也就是最开始时候的状态,回退最终也只能回退到 firstState,不能再退了
27+
* 类似打开sublime编辑文件,无论怎么改动,撤退到最后一步,其实就是是文件打开时候的状态
28+
* 同理 在 setWork 的时候,应该进行 undoRedoHistory.addState(firstState)
29+
*/
30+
// let firstState = cloneDeep(store.state)
31+
// undoRedoHistory.addState(firstState)
1932

2033
store.subscribe((mutation, state) => {
2134
const { type } = mutation

0 commit comments

Comments
 (0)