From a52f74d0927d6b70b8c63cf8640a9e588e0f8792 Mon Sep 17 00:00:00 2001 From: alemi Date: Wed, 12 Apr 2023 04:21:02 +0200 Subject: [PATCH] fix: move cursor in insert, error if not connected --- src/client/nvim/codemp.lua | 14 ++++++++++++-- src/client/nvim/main.rs | 5 +---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/client/nvim/codemp.lua b/src/client/nvim/codemp.lua index 405f61d..3e75531 100644 --- a/src/client/nvim/codemp.lua +++ b/src/client/nvim/codemp.lua @@ -27,7 +27,7 @@ local function hook_callbacks(path, buffer) } ) vim.api.nvim_create_autocmd( - { "CursorMoved" }, + { "CursorMoved", "CursorMovedI" }, { callback = function(_) local cursor = vim.api.nvim_win_get_cursor(0) @@ -49,7 +49,6 @@ local function unhook_callbacks(buffer) vim.keymap.del('i', '', { buffer = buffer }) end - vim.api.nvim_create_user_command('Connect', function(args) if M.jobid ~= nil then @@ -71,6 +70,9 @@ vim.api.nvim_create_user_command('Connect', on_stderr = function(_, data, _) print(vim.fn.join(data, "\n")) end, } ) + if M.jobid <= 0 then + print("[!] could not start codemp client") + end end, { nargs='?', bang=true }) @@ -83,6 +85,10 @@ vim.api.nvim_create_user_command('Stop', vim.api.nvim_create_user_command('Share', function(args) + if M.jobid <= 0 then + print("[!] connect to codemp server first") + return + end local path = args.fargs[1] local bufnr = vim.api.nvim_get_current_buf() local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) @@ -95,6 +101,10 @@ vim.api.nvim_create_user_command('Share', vim.api.nvim_create_user_command('Join', function(args) + if M.jobid <= 0 then + print("[!] connect to codemp server first") + return + end local path = args.fargs[1] local bufnr = vim.api.nvim_get_current_buf() hook_callbacks(path, bufnr) diff --git a/src/client/nvim/main.rs b/src/client/nvim/main.rs index 8b46e49..6ec0362 100644 --- a/src/client/nvim/main.rs +++ b/src/client/nvim/main.rs @@ -164,10 +164,7 @@ impl Handler for NeovimHandler { if let Err(e) = _b.clear_namespace(ns, 0, -1).await { error!("could not clear previous cursor highlight: {}", e); } - if let Err(e) = _b.add_highlight( - ns, "ErrorMsg", - cur.row as i64 - 1, cur.col as i64 - 1, cur.col as i64 - ).await { + if let Err(e) = _b.add_highlight(ns, "ErrorMsg", cur.row-1, cur.col, cur.col+1).await { error!("could not create highlight for cursor: {}", e); } });