Fix suppression flag timing with counter instead of boolean

This commit is contained in:
Jared Miller 2026-01-27 16:18:15 -05:00
parent 73ee70c52a
commit 7b81777d9d
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C

View file

@ -9,7 +9,7 @@ const DAEMON_URL = process.env.COLLABD_URL || "ws://localhost:4040/ws";
let ws: WebSocket | null = null;
let doc: Y.Doc | null = null;
let text: Y.Text | null = null;
let suppressLocal = false;
let suppressLocal = 0;
function send(msg: object) {
console.log(JSON.stringify(msg));
@ -24,7 +24,7 @@ function connect(roomName: string) {
// when remote changes come in, notify vim
text.observe(() => {
if (!suppressLocal) {
if (suppressLocal === 0) {
send({ type: "content", text: text?.toString() || "" });
}
});
@ -43,12 +43,12 @@ function connect(roomName: string) {
case "update": {
if (!doc) break;
try {
suppressLocal = true;
suppressLocal++;
Y.applyUpdate(doc, new Uint8Array(msg.data));
suppressLocal = false;
suppressLocal--;
send({ type: "content", text: text?.toString() || "" });
} catch (err) {
suppressLocal = false;
suppressLocal--;
console.error("failed to apply yjs update:", err);
send({ type: "error", message: "failed to apply remote update" });
}