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
|
# collab.vim - collaborative editing adapter for collabd
|
||||||
# requires: bun, collabd daemon running
|
# requires: bun, collabd daemon running
|
||||||
|
|
||||||
|
highlight PeerCursor ctermbg=yellow guibg=yellow ctermfg=black guifg=black
|
||||||
|
|
||||||
var bridge_job: job = null_job
|
var bridge_job: job = null_job
|
||||||
var bridge_channel: channel = null_channel
|
var bridge_channel: channel = null_channel
|
||||||
var connected = false
|
var connected = false
|
||||||
var ready = false
|
var ready = false
|
||||||
var room = ""
|
var room = ""
|
||||||
var suppressing = false
|
var suppressing = false
|
||||||
|
var peer_match_ids: dict<number> = {}
|
||||||
|
|
||||||
# path to bridge script (adjust as needed)
|
# path to bridge script (adjust as needed)
|
||||||
const bridge_script = expand('<sfile>:p:h') .. '/bridge.ts'
|
const bridge_script = expand('<sfile>:p:h') .. '/bridge.ts'
|
||||||
|
|
@ -42,6 +45,8 @@ def OnOutput(ch: channel, msg: string)
|
||||||
ApplyRemoteContent(data.text)
|
ApplyRemoteContent(data.text)
|
||||||
elseif data.type == 'peers'
|
elseif data.type == 'peers'
|
||||||
echom '[collab] peers: ' .. data.count
|
echom '[collab] peers: ' .. data.count
|
||||||
|
elseif data.type == 'cursor'
|
||||||
|
ShowPeerCursor(data.data)
|
||||||
elseif data.type == 'error'
|
elseif data.type == 'error'
|
||||||
echoerr '[collab] ' .. data.message
|
echoerr '[collab] ' .. data.message
|
||||||
endif
|
endif
|
||||||
|
|
@ -69,6 +74,30 @@ def SendBuffer()
|
||||||
Send({type: 'content', text: content})
|
Send({type: 'content', text: content})
|
||||||
enddef
|
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)
|
export def Connect(room_name: string)
|
||||||
if bridge_job != null_job
|
if bridge_job != null_job
|
||||||
Disconnect()
|
Disconnect()
|
||||||
|
|
@ -112,6 +141,7 @@ export def Disconnect()
|
||||||
bridge_job = null_job
|
bridge_job = null_job
|
||||||
bridge_channel = null_channel
|
bridge_channel = null_channel
|
||||||
endif
|
endif
|
||||||
|
ClearPeerCursors()
|
||||||
connected = false
|
connected = false
|
||||||
ready = false
|
ready = false
|
||||||
room = ""
|
room = ""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue