Display peer cursors in vim with yellow highlight
This commit is contained in:
parent
e467881a8c
commit
80da4f9f5b
1 changed files with 30 additions and 0 deletions
|
|
@ -3,12 +3,15 @@ vim9script
|
|||
# collab.vim - collaborative editing adapter for collabd
|
||||
# requires: bun, collabd daemon running
|
||||
|
||||
highlight PeerCursor ctermbg=yellow guibg=yellow ctermfg=black guifg=black
|
||||
|
||||
var bridge_job: job = null_job
|
||||
var bridge_channel: channel = null_channel
|
||||
var connected = false
|
||||
var ready = false
|
||||
var room = ""
|
||||
var suppressing = false
|
||||
var peer_match_ids: dict<number> = {}
|
||||
|
||||
# path to bridge script (adjust as needed)
|
||||
const bridge_script = expand('<sfile>:p:h') .. '/bridge.ts'
|
||||
|
|
@ -42,6 +45,8 @@ def OnOutput(ch: channel, msg: string)
|
|||
ApplyRemoteContent(data.text)
|
||||
elseif data.type == 'peers'
|
||||
echom '[collab] peers: ' .. data.count
|
||||
elseif data.type == 'cursor'
|
||||
ShowPeerCursor(data.data)
|
||||
elseif data.type == 'error'
|
||||
echoerr '[collab] ' .. data.message
|
||||
endif
|
||||
|
|
@ -69,6 +74,30 @@ def SendBuffer()
|
|||
Send({type: 'content', text: content})
|
||||
enddef
|
||||
|
||||
def ShowPeerCursor(data: dict<any>)
|
||||
const client_id = string(data.clientId)
|
||||
|
||||
# Clear previous highlight for this peer
|
||||
if has_key(peer_match_ids, client_id)
|
||||
silent! matchdelete(peer_match_ids[client_id])
|
||||
endif
|
||||
|
||||
# Highlight the cursor position (line, col are 0-indexed from bridge)
|
||||
const line_nr = data.line + 1
|
||||
const col_nr = data.col + 1
|
||||
|
||||
# Create a 1-char highlight at cursor position
|
||||
const pattern = '\%' .. line_nr .. 'l\%' .. col_nr .. 'c.'
|
||||
peer_match_ids[client_id] = matchadd('PeerCursor', pattern, 10)
|
||||
enddef
|
||||
|
||||
def ClearPeerCursors()
|
||||
for id in values(peer_match_ids)
|
||||
silent! matchdelete(id)
|
||||
endfor
|
||||
peer_match_ids = {}
|
||||
enddef
|
||||
|
||||
export def Connect(room_name: string)
|
||||
if bridge_job != null_job
|
||||
Disconnect()
|
||||
|
|
@ -112,6 +141,7 @@ export def Disconnect()
|
|||
bridge_job = null_job
|
||||
bridge_channel = null_channel
|
||||
endif
|
||||
ClearPeerCursors()
|
||||
connected = false
|
||||
ready = false
|
||||
room = ""
|
||||
|
|
|
|||
Loading…
Reference in a new issue