@@ -37,16 +37,27 @@ const Undo = Module({
3737
3838 const {
3939 isUndo,
40- isRedo
40+ isRedo,
41+ noChange
4142 } = this . analyzeStates ( states ) ;
4243
43- console . log ( Object . assign ( { } , {
44- states,
45- isUndo,
46- isRedo
47- } ) ) ;
44+ console . log (
45+ JSON . parse (
46+ JSON . stringify ( {
47+ states,
48+ currentHistoryIndex,
49+ history,
50+ isUndo,
51+ isRedo,
52+ noChange
53+ } )
54+ )
55+ ) ;
4856
49- if ( ! isUndo && ! isRedo ) {
57+ if ( noChange ) {
58+ props . history [ currentHistoryIndex ] = states . current ;
59+ } else if ( ! isUndo && ! isRedo ) {
60+ props . history . length = currentHistoryIndex + 1 ;
5061 props . history . push ( states . current ) ;
5162 props . currentHistoryIndex += 1 ;
5263 } else if ( isUndo ) {
@@ -71,7 +82,7 @@ const Undo = Module({
7182
7283 createHistoryState ( ) {
7384 const { mediator, props } = this ;
74- const editableContentString = DOM . nodesToHTMLString ( DOM . cloneNodes ( props . contentEditableElem , { trim : true } ) ) . replace ( / \u200B / g, '' ) ;
85+ const editableContentString = DOM . nodesToHTMLString ( DOM . cloneNodes ( props . contentEditableElem , { trim : true } ) ) . replace ( / \u200B / g, '' ) . trim ( ) ;
7586 const selectionRangeCoordinates = mediator . get ( 'selection:range:coordinates' ) ;
7687
7788 return {
@@ -90,13 +101,20 @@ const Undo = Module({
90101 } = states ;
91102 let isUndo = beforePrevious && current . editableContentString === beforePrevious . editableContentString ;
92103 let isRedo = next && current . editableContentString === next . editableContentString ;
104+ let noChange = previous && current . editableContentString === previous . editableContentString ;
93105
94106 isUndo = isUndo || false ;
95107 isRedo = isRedo || false ;
108+ noChange = noChange || false ;
96109
110+ if ( ! isUndo && ! isRedo && ! noChange && previous ) {
111+ console . log ( previous . editableContentString ) ;
112+ console . log ( current . editableContentString ) ;
113+ }
97114 return {
98115 isUndo,
99- isRedo
116+ isRedo,
117+ noChange
100118 }
101119 }
102120 }
0 commit comments