Skip to content

Commit

Permalink
perf(json-crdt-extensions): ⚡️ just cursor directly to insertion end
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Nov 11, 2024
1 parent ce233cc commit 1e86004
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/json-crdt-extensions/peritext/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ export class Editor<T = string> implements Printable {
if (!cursor.isCollapsed()) this.delRange(cursor);
const after = cursor.start.clone();
after.refAfter();
this.txt.ins(after.id, text);
after.step(text.length);
cursor.set(after, after, CursorAnchor.Start);
const txt = this.txt;
const textId = txt.ins(after.id, text);
const shift = text.length - 1;
const point = txt.point(shift ? tick(textId, shift) : textId, Anchor.After);
cursor.set(point, point, CursorAnchor.Start);
}

/**
Expand Down

0 comments on commit 1e86004

Please sign in to comment.