diff options
| -rw-r--r-- | lua/clever_f/host_adapter.lua | 34 | ||||
| -rw-r--r-- | tests/plugin_smoke.lua | 19 |
2 files changed, 51 insertions, 2 deletions
diff --git a/lua/clever_f/host_adapter.lua b/lua/clever_f/host_adapter.lua index 724e9da..a4ec77d 100644 --- a/lua/clever_f/host_adapter.lua +++ b/lua/clever_f/host_adapter.lua @@ -285,13 +285,43 @@ function HostAdapter:set_operator_inclusive(enabled) if type(enabled) ~= "boolean" then fail("operator inclusivity must be a Boolean", 2) end - if enabled then - self:runtime().api.nvim_cmd({ + if not enabled then + return + end + + local runtime = self:runtime() + local api = runtime.api + local selection + if type(api.nvim_get_option_value) == "function" then + selection = api.nvim_get_option_value("selection", { scope = "global" }) + end + if selection ~= "exclusive" then + api.nvim_cmd({ cmd = "normal", bang = true, args = { "v" }, }, {}) + return end + if type(api.nvim_set_option_value) ~= "function" + or type(runtime.schedule) ~= "function" + then + fail("HostAdapter cannot preserve exclusive selection during an operator", 2) + end + + api.nvim_set_option_value("selection", "inclusive", { scope = "global" }) + local ok, command_error = pcall(api.nvim_cmd, { + cmd = "normal", + bang = true, + args = { "v" }, + }, {}) + if not ok then + api.nvim_set_option_value("selection", selection, { scope = "global" }) + error(command_error, 0) + end + runtime.schedule(function() + api.nvim_set_option_value("selection", selection, { scope = "global" }) + end) end local function string_bytes(value) diff --git a/tests/plugin_smoke.lua b/tests/plugin_smoke.lua index c422490..8a3cfc9 100644 --- a/tests/plugin_smoke.lua +++ b/tests/plugin_smoke.lua @@ -50,6 +50,25 @@ same(1, vim.api.nvim_win_get_cursor(0)[2]) feed("<Esc>") clever_f.Reset() +local saved_selection = vim.o.selection +vim.o.selection = "exclusive" +vim.api.nvim_buf_set_lines(0, 0, -1, true, { "hoge fuge piye poye" }) +vim.api.nvim_win_set_cursor(0, { 1, 0 }) +feed("dfe") +vim.wait(10) +same(" fuge piye poye", vim.api.nvim_get_current_line()) +same("exclusive", vim.o.selection) +clever_f.Reset() + +vim.api.nvim_buf_set_lines(0, 0, -1, true, { "hoge fuge piye poye" }) +vim.api.nvim_win_set_cursor(0, { 1, 0 }) +feed("dte") +vim.wait(10) +same("e fuge piye poye", vim.api.nvim_get_current_line()) +same("exclusive", vim.o.selection) +clever_f.Reset() +vim.o.selection = saved_selection + vim.api.nvim_buf_set_lines(0, 0, -1, true, { "hoge fuge piye poye" }) vim.api.nvim_win_set_cursor(0, { 1, 0 }) feed("dfe") |
