feat: follow end of cursor that is being moved

This commit is contained in:
əlemi 2024-09-25 04:07:18 +02:00
parent 8a93fb5dc2
commit a98763217a
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -32,6 +32,8 @@ local function fetch_workspaces_list()
end) end)
end end
local last_jump = { 0, 0 }
---@param ws Workspace ---@param ws Workspace
local function register_cursor_callback(ws) local function register_cursor_callback(ws)
local controller = ws.cursor local controller = ws.cursor
@ -133,8 +135,14 @@ local function register_cursor_handler(ws)
if curr_buf ~= buf_id then if curr_buf ~= buf_id then
vim.api.nvim_win_set_buf(win, buf_id) vim.api.nvim_win_set_buf(win, buf_id)
end end
-- keep centered the cursor end that is currently being moved, but prefer start
if event.start[1] == last_jump[1] and event.start[2] == last_jump[2] then
vim.api.nvim_win_set_cursor(win, { event.finish[1] + 1, event.finish[2] })
else
vim.api.nvim_win_set_cursor(win, { event.start[1] + 1, event.start[2] }) vim.api.nvim_win_set_cursor(win, { event.start[1] + 1, event.start[2] })
end end
last_jump = event.start
end
end end
end end
end end