Skip to content

Commit 98e209a

Browse files
committed
#32 - Some code cleanup + tweaks
1 parent b73dda8 commit 98e209a

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

src/scripts/modules/Selection.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -672,15 +672,6 @@ const Selection = Module({
672672
let startContainer = dom.el[0];
673673
let endContainer = dom.el[0];
674674

675-
console.log({
676-
dom,
677-
startContainer,
678-
endContainer,
679-
startCoordinates,
680-
endCoordinates,
681-
rangeCoordinates
682-
})
683-
684675
while (startCoordinates.length) {
685676
let startIndex = startCoordinates.shift();
686677
startContainer = startContainer.childNodes[startIndex];

src/scripts/modules/Undo.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)