Commit a968260fd1c9d543e7798a6292772a119a182b3d

Authored by ly525
1 parent 5ace866a

fix: confirm the firstState for the undoRedoPlugin

front-end/h5/src/store/plugins/undo-redo/index.js
@@ -8,14 +8,27 @@ import undoRedoHistory from './History' @@ -8,14 +8,27 @@ import undoRedoHistory from './History'
8 // const unRecordHistoryMutationTypes = ['editor/setElementCommonStyle'] 8 // const unRecordHistoryMutationTypes = ['editor/setElementCommonStyle']
9 const recordHistoryMutationTypes = [ 9 const recordHistoryMutationTypes = [
10 'editor/recordRect', 10 'editor/recordRect',
11 - 'editor/elementManager' 11 + 'editor/elementManager',
  12 + 'editor/setEditingPage' // 用作 firstState,类似打开文件编辑之前的原始文件
12 ] 13 ]
13 14
14 const undoRedoPlugin = (store) => { 15 const undoRedoPlugin = (store) => {
15 // initialize and save the starting stage 16 // initialize and save the starting stage
16 undoRedoHistory.init(store) 17 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)
19 32
20 store.subscribe((mutation, state) => { 33 store.subscribe((mutation, state) => {
21 const { type } = mutation 34 const { type } = mutation