···533533 };
534534535535 ws.onclose = () => {
536536+ clearTimeout(wsEditTimer);
537537+ pendingDeltas = [];
536538 stopHeartbeat();
537539 updatePresence([]);
538540 scheduleReconnect();
···643645644646 // Queue a set of deltas and flush after a short debounce.
645647 function queueDeltas(deltas) {
646646- if (!ws || ws.readyState !== WebSocket.OPEN || applyingRemote) return;
648648+ if (!ws || ws.readyState !== WebSocket.OPEN) return;
647649 pendingDeltas = pendingDeltas.concat(deltas);
648650 clearTimeout(wsEditTimer);
649651 wsEditTimer = setTimeout(flushDeltas, 50);
···658660 pendingDeltas = [];
659661 }
660662661661- // sendEdit is kept for any future callers; Milkdown switches to diffToOps
662662- // in Chunk 4 and no longer calls this directly.
663663+ // sendEdit sends a full-document replacement via the granular-delta path.
664664+ // to: -1 is a sentinel meaning "end of document" — the server OT engine
665665+ // clamps it to len(documentText), and applyRemoteEdit clamps it to docLen.
666666+ // Milkdown switches to diffToOps in Chunk 4 and no longer calls this directly.
663667 function sendEdit(content) {
664664- if (!ws || ws.readyState !== WebSocket.OPEN || applyingRemote) return;
668668+ if (!ws || ws.readyState !== WebSocket.OPEN) return;
665669 queueDeltas([{ from: 0, to: -1, insert: content }]);
666670 }
667671