Skip to content

Commit 893d6d3

Browse files
committed
feat(json-crdt-peritext-ui): 🎸 cleanup undo history implementations
1 parent 7844476 commit 893d6d3

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ export class UndoRedoController implements UndoCollector, UiLifeCycles, Printabl
5757
source: doPatch,
5858
patch,
5959
});
60-
console.log('doPatch', doPatch + '');
61-
console.log('undoPatch', patch + '');
60+
// console.log('doPatch', doPatch + '');
61+
// console.log('undoPatch', patch + '');
6262
return [doPatch, this._redo] as RedoItem<Patch, Patch>;
6363
};
6464

@@ -70,8 +70,8 @@ export class UndoRedoController implements UndoCollector, UiLifeCycles, Printabl
7070
source: doPatch,
7171
patch: redoPatch,
7272
});
73-
console.log('doPatch', doPatch + '');
74-
console.log('redoPatch', redoPatch + '');
73+
// console.log('doPatch', doPatch + '');
74+
// console.log('redoPatch', redoPatch + '');
7575
return [redoPatch, this._undo] as RedoItem<Patch, Patch>;
7676
};
7777

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,15 @@ export class WebUndo implements UndoManager, UiLifeCycles {
4040
const activeElement = document.activeElement;
4141
try {
4242
this._push = true;
43-
const style = el.style;
44-
this.undo.push(undo as UndoItem);
4543
this.redo = [];
4644
el.setAttribute('aria-hidden', 'false');
47-
style.visibility = 'visible';
4845
el.focus();
49-
document.execCommand?.('insertText', false, '|');
46+
document.execCommand?.('insertText', false, '.');
47+
const tlen = this.el.innerText.length;
48+
if (tlen - 1 === this.undo.length) this.undo.push(undo as UndoItem);
5049
} finally {
5150
el.blur();
5251
this._push = false;
53-
// style.visibility = 'hidden';
5452
el.setAttribute('aria-hidden', 'true');
5553
(activeElement as HTMLElement)?.focus?.();
5654
}
@@ -64,15 +62,11 @@ export class WebUndo implements UndoManager, UiLifeCycles {
6462
el.contentEditable = 'true';
6563
el.setAttribute('aria-hidden', 'true');
6664
const style = el.style;
67-
// style.opacity = '0';
68-
style.position = 'fixed';
69-
// style.top = '-1000px';
70-
style.top = '10px';
71-
style.left = '10px';
7265
style.pointerEvents = 'none';
73-
// style.fontSize = '2px';
74-
style.fontSize = '8px';
75-
// style.visibility = 'hidden';
66+
style.position = 'fixed';
67+
style.fontSize = '1px';
68+
style.top = '-1000px';
69+
style.opacity = '0';
7670
document.body.appendChild(el);
7771
el.addEventListener('focus', this.onFocus);
7872
el.addEventListener('input', this.onInput);
@@ -86,14 +80,16 @@ export class WebUndo implements UndoManager, UiLifeCycles {
8680
}
8781

8882
public readonly onFocus = () => {
89-
setTimeout(() => this.el.blur(), 0);
83+
const el = this.el;
84+
setTimeout(() => el.blur(), 0);
9085
};
9186

9287
public readonly onInput = () => {
9388
const tlen = this.el.innerText.length;
9489
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();
90+
const {undo, redo} = this;
91+
while (undo.length && undo.length > tlen) this._undo();
92+
while (redo.length && undo.length < tlen) this._redo();
9793
}
9894
};
9995
}

src/json-crdt-peritext-ui/events/defaults/PeritextEventDefaults.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,7 @@ export class PeritextEventDefaults implements PeritextEventHandlerMap {
372372
};
373373

374374
public readonly annals = (event: CustomEvent<events.AnnalsDetail>) => {
375-
const {action, patch} = event.detail;
375+
const {patch} = event.detail;
376376
this.txt.model.applyPatch(patch);
377-
console.log('annals', action, patch);
378377
};
379378
}

0 commit comments

Comments
 (0)