Skip to content

Commit 7844476

Browse files
committed
perf(json-crdt-peritext-ui): ⚡️ do not track of undo element text length
1 parent c777adf commit 7844476

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/json-crdt-peritext-ui/dom/undo/WebUndo.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ export class WebUndo implements UndoManager, UiLifeCycles {
1111
private _push: boolean = false;
1212
/** The DOM element, which keeps text content for native undo/redo integration. */
1313
protected el!: HTMLElement;
14-
/** The last known text contents length of the `el`. */
15-
protected tlen: number = 0;
1614
/** Undo stack. */
1715
public undo: UndoItem[] = [];
1816
/** Redo stack. */
@@ -92,13 +90,10 @@ export class WebUndo implements UndoManager, UiLifeCycles {
9290
};
9391

9492
public readonly onInput = () => {
95-
const text = this.el.innerText;
96-
if (this._push) {
97-
this.tlen = text.length;
98-
console.log(this.tlen, this.undo.length);
99-
} else {
100-
while (this.undo.length && this.undo.length > text.length) this._undo();
101-
while (this.redo.length && this.undo.length < text.length) this._redo();
93+
const tlen = this.el.innerText.length;
94+
if (!this._push) {
95+
while (this.undo.length && this.undo.length > tlen) this._undo();
96+
while (this.redo.length && this.undo.length < tlen) this._redo();
10297
}
10398
};
10499
}

0 commit comments

Comments
 (0)