From a1864e588096e236e30a2856bfde738cdea041d0 Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Tue, 27 Jan 2026 20:49:54 -0500 Subject: [PATCH] Generate bridge clientId once --- adapters/vim/bridge.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/adapters/vim/bridge.ts b/adapters/vim/bridge.ts index 8e096f4..16872f8 100644 --- a/adapters/vim/bridge.ts +++ b/adapters/vim/bridge.ts @@ -10,6 +10,7 @@ let ws: WebSocket | null = null; let doc: Y.Doc | null = null; let text: Y.Text | null = null; let suppressLocal = 0; +let clientId: number | null = null; function send(msg: object) { console.log(JSON.stringify(msg)); @@ -32,6 +33,7 @@ function connect(roomName: string) { ws = new WebSocket(DAEMON_URL); ws.onopen = () => { + clientId = Math.floor(Math.random() * 1000000); ws?.send(JSON.stringify({ type: "join", room: roomName })); send({ type: "connected", room: roomName }); }; @@ -161,12 +163,17 @@ for await (const chunk of Bun.stdin.stream()) { setContent(msg.text); break; case "cursor": - if (ws && msg.line !== undefined && msg.col !== undefined) { + if ( + ws && + clientId !== null && + msg.line !== undefined && + msg.col !== undefined + ) { ws.send( JSON.stringify({ type: "awareness", data: { - clientId: Math.floor(Math.random() * 1000000), + clientId, cursor: { line: msg.line, col: msg.col }, }, }),