Skip to content

Commit 148530c

Browse files
committed
fix: rare infinite loop in editor history snapshot
1 parent f59a73b commit 148530c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/editor/Editor.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1370,12 +1370,24 @@ define(function (require, exports, module) {
13701370
const cm = this._codeMirror;
13711371
const self = this;
13721372
cm.operation(function () {
1373-
let newHistory = self.getHistory();
1373+
let newHistory = self.getHistory(), historyLength;
13741374
let lastHistoryItem = newHistory.done && newHistory.done.length
13751375
&& history.done[history.done.length -1];
13761376
while(lastHistoryItem && lastHistoryItem.restorePointName !== restorePointName) {
1377+
newHistory = self.getHistory();
1378+
historyLength = newHistory?.done?.length;
13771379
cm.undoSelection();
13781380
newHistory = self.getHistory();
1381+
if(historyLength === newHistory?.done?.length) {
1382+
// undo selection didnt do anything, try undo
1383+
cm.undo();
1384+
newHistory = self.getHistory();
1385+
if(historyLength === newHistory?.done?.length) {
1386+
// we cant undo, and this will go into an infinite loop if we continue.
1387+
console.error("Could not undo history to restore snapshot!");
1388+
break;
1389+
}
1390+
}
13791391
lastHistoryItem = newHistory.done && newHistory.done.length
13801392
&& newHistory.done[newHistory.done.length -1];
13811393
}

0 commit comments

Comments
 (0)