Send local cursor position to peers
This commit is contained in:
parent
80da4f9f5b
commit
5275c99976
2 changed files with 23 additions and 0 deletions
|
|
@ -160,6 +160,19 @@ for await (const chunk of Bun.stdin.stream()) {
|
||||||
case "content":
|
case "content":
|
||||||
setContent(msg.text);
|
setContent(msg.text);
|
||||||
break;
|
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":
|
case "disconnect":
|
||||||
ws?.close();
|
ws?.close();
|
||||||
send({ type: "disconnected" });
|
send({ type: "disconnected" });
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,15 @@ def SendBuffer()
|
||||||
Send({type: 'content', text: content})
|
Send({type: 'content', text: content})
|
||||||
enddef
|
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<any>)
|
def ShowPeerCursor(data: dict<any>)
|
||||||
const client_id = string(data.clientId)
|
const client_id = string(data.clientId)
|
||||||
|
|
||||||
|
|
@ -131,6 +140,7 @@ export def Connect(room_name: string)
|
||||||
augroup CollabVim
|
augroup CollabVim
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd TextChanged,TextChangedI * call SendBuffer()
|
autocmd TextChanged,TextChangedI * call SendBuffer()
|
||||||
|
autocmd CursorMoved,CursorMovedI <buffer> call SendCursor()
|
||||||
augroup END
|
augroup END
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue