diff options
Diffstat (limited to 'lua/clever_f/host_adapter.lua')
| -rw-r--r-- | lua/clever_f/host_adapter.lua | 34 |
1 files changed, 32 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) |
