chore: cursor callback fns get just the controller

This commit is contained in:
əlemi 2024-09-26 05:37:51 +02:00
parent 3a40a01fb5
commit e8005fbeab
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -34,13 +34,13 @@ end
local last_jump = { 0, 0 } local last_jump = { 0, 0 }
---@param ws Workspace ---@param controller CursorController
local function register_cursor_callback(ws) ---@param name string
local controller = ws.cursor local function register_cursor_callback(controller, name)
local once = true local once = true
vim.api.nvim_create_autocmd({"CursorMoved", "CursorMovedI", "ModeChanged"}, { vim.api.nvim_create_autocmd({"CursorMoved", "CursorMovedI", "ModeChanged"}, {
group = vim.api.nvim_create_augroup("codemp-workspace-" .. ws.name, { clear = true }), group = vim.api.nvim_create_augroup("codemp-workspace-" .. name, { clear = true }),
callback = function (ev) callback = function (_ev)
if CODEMP.ignore_following_action then if CODEMP.ignore_following_action then
CODEMP.ignore_following_action = false CODEMP.ignore_following_action = false
return return
@ -72,9 +72,8 @@ local function register_cursor_callback(ws)
}) })
end end
---@param ws Workspace ---@param controller CursorController
local function register_cursor_handler(ws) local function register_cursor_handler(controller)
local controller = ws.cursor
local async = vim.loop.new_async(vim.schedule_wrap(function () local async = vim.loop.new_async(vim.schedule_wrap(function ()
while true do while true do
local event = controller:try_recv():await() local event = controller:try_recv():await()
@ -157,8 +156,8 @@ local function join(workspace)
print(" <> joining workspace " .. workspace .. " ...") print(" <> joining workspace " .. workspace .. " ...")
CODEMP.client:join_workspace(workspace):and_then(function (ws) CODEMP.client:join_workspace(workspace):and_then(function (ws)
print(" >< joined workspace " .. ws.name) print(" >< joined workspace " .. ws.name)
register_cursor_callback(ws) register_cursor_callback(ws.cursor, ws.name)
register_cursor_handler(ws) register_cursor_handler(ws.cursor)
CODEMP.workspace = ws CODEMP.workspace = ws
for _, user in pairs(CODEMP.workspace:user_list()) do for _, user in pairs(CODEMP.workspace:user_list()) do
buffers.users[user] = "" buffers.users[user] = ""
@ -210,5 +209,4 @@ return {
leave = leave, leave = leave,
map = user_hl, map = user_hl,
list = fetch_workspaces_list, list = fetch_workspaces_list,
setup_colors = setup_colors,
} }