summaryrefslogtreecommitdiff
path: root/lua/clever_f
diff options
context:
space:
mode:
authorJackson Moore <jacksonmoore@tuta.io>2026-09-04 18:04:58 +0200
committerJackson Moore <jacksonmoore@tuta.io>2026-09-04 18:04:58 +0200
commitd6ac0e7ab3c48ffdf1e2ae15dcd6be4f9780e369 (patch)
tree5b4e40d6463b2d7007ca2ec00f86647116389c13 /lua/clever_f
parentaafc65fb4dd2fe8438fc6c0d77ef1df5b2f52bf1 (diff)
Preserve operator inclusivity with exclusive selection
Diffstat (limited to 'lua/clever_f')
-rw-r--r--lua/clever_f/host_adapter.lua34
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)