From 5275c9997643c442c20552de2d3af358de17268b Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Tue, 27 Jan 2026 20:44:36 -0500 Subject: [PATCH] Send local cursor position to peers --- adapters/vim/bridge.ts | 13 +++++++++++++ adapters/vim/collab.vim | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/adapters/vim/bridge.ts b/adapters/vim/bridge.ts index cfb0928..8e096f4 100644 --- a/adapters/vim/bridge.ts +++ b/adapters/vim/bridge.ts @@ -160,6 +160,19 @@ for await (const chunk of Bun.stdin.stream()) { case "content": setContent(msg.text); break; + case "cursor": + if (ws && msg.line !== undefined && msg.col !== undefined) { + ws.send( + JSON.stringify({ + type: "awareness", + data: { + clientId: Math.floor(Math.random() * 1000000), + cursor: { line: msg.line, col: msg.col }, + }, + }), + ); + } + break; case "disconnect": ws?.close(); send({ type: "disconnected" }); diff --git a/adapters/vim/collab.vim b/adapters/vim/collab.vim index 4de58d3..e261243 100644 --- a/adapters/vim/collab.vim +++ b/adapters/vim/collab.vim @@ -74,6 +74,15 @@ def SendBuffer() Send({type: 'content', text: content}) enddef +def SendCursor() + if !connected + return + endif + const pos = getpos('.') + # pos is [bufnum, line, col, off] - line/col are 1-indexed + Send({type: 'cursor', line: pos[1] - 1, col: pos[2] - 1}) +enddef + def ShowPeerCursor(data: dict) const client_id = string(data.clientId) @@ -131,6 +140,7 @@ export def Connect(room_name: string) augroup CollabVim autocmd! autocmd TextChanged,TextChangedI * call SendBuffer() + autocmd CursorMoved,CursorMovedI call SendCursor() augroup END enddef