diff --git a/adapters/vim/bridge.ts b/adapters/vim/bridge.ts index cdee6c9..bbe6ac8 100644 --- a/adapters/vim/bridge.ts +++ b/adapters/vim/bridge.ts @@ -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" }); }