From 5b90a8e5f9a51a7ad1add80a4fe68253788f077e Mon Sep 17 00:00:00 2001 From: Carlos Gutierrez Date: Sun, 11 Jan 2026 15:42:34 -0500 Subject: [PATCH] fix: make transform keymaps work in both normal and visual modes Fixed keymaps to use command strings instead of function references: - ctt (visual): Uses :CoderTransformVisual - ctt (normal): Uses CoderTransformCursor - ctT (normal): Uses CoderTransform Also fixed CoderTransformVisual to properly receive line range from opts. --- lua/codetyper/commands.lua | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/lua/codetyper/commands.lua b/lua/codetyper/commands.lua index 0272107..65d5a75 100644 --- a/lua/codetyper/commands.lua +++ b/lua/codetyper/commands.lua @@ -687,8 +687,10 @@ function M.setup() cmd_transform_at_cursor() end, { desc = "Transform /@ @/ tag at cursor" }) - vim.api.nvim_create_user_command("CoderTransformVisual", function() - cmd_transform_visual() + vim.api.nvim_create_user_command("CoderTransformVisual", function(opts) + local start_line = opts.line1 + local end_line = opts.line2 + cmd_transform_range(start_line, end_line) end, { range = true, desc = "Transform /@ @/ tags in visual selection" }) -- Setup default keymaps @@ -698,25 +700,22 @@ end --- Setup default keymaps for transform commands function M.setup_keymaps() -- Visual mode: transform selected /@ @/ tags - vim.keymap.set("v", "ctt", function() - -- Exit visual mode and run the command - vim.cmd("normal! ") - vim.schedule(function() - local start_line = vim.fn.line("'<") - local end_line = vim.fn.line("'>") - cmd_transform_range(start_line, end_line) - end) - end, { desc = "Coder: Transform selected tags" }) + vim.keymap.set("v", "ctt", ":CoderTransformVisual", { + silent = true, + desc = "Coder: Transform selected tags" + }) -- Normal mode: transform tag at cursor - vim.keymap.set("n", "ctt", function() - cmd_transform_at_cursor() - end, { desc = "Coder: Transform tag at cursor" }) + vim.keymap.set("n", "ctt", "CoderTransformCursor", { + silent = true, + desc = "Coder: Transform tag at cursor" + }) -- Normal mode: transform all tags in file - vim.keymap.set("n", "ctT", function() - cmd_transform() - end, { desc = "Coder: Transform all tags in file" }) + vim.keymap.set("n", "ctT", "CoderTransform", { + silent = true, + desc = "Coder: Transform all tags in file" + }) end return M