From 90532ef0ad7c549438e9014ad80d12ba8c0993d4 Mon Sep 17 00:00:00 2001 From: Theo Brigitte Date: Tue, 30 Sep 2025 19:28:24 +0200 Subject: [PATCH 1/3] Allow customizable window_navigation and scrolling keymaps --- README.md | 14 ++++++- lua/claude-code/config.lua | 60 +++++++++++++++++++++++---- lua/claude-code/keymaps.lua | 24 +++++------ tests/spec/config_validation_spec.lua | 10 ++--- 4 files changed, 81 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 093dd41..868b550 100644 --- a/README.md +++ b/README.md @@ -146,8 +146,18 @@ require("claude-code").setup({ verbose = "cV", -- Normal mode keymap for Claude Code with verbose flag }, }, - window_navigation = true, -- Enable window navigation keymaps () - scrolling = true, -- Enable scrolling keymaps () for page up/down + window_navigation = { + enabled = true, -- Enable window navigation keymaps + left = '', -- Move to left window + down = '', -- Move to down window + up = '', -- Move to up window + right = '', -- Move to right window + }, + scrolling = { + enabled = true, -- Enable scrolling keymaps + page_down = '', -- Scroll down one page + page_up = '', -- Scroll up one page + }, } }) ``` diff --git a/lua/claude-code/config.lua b/lua/claude-code/config.lua index 07d1a2c..15be871 100644 --- a/lua/claude-code/config.lua +++ b/lua/claude-code/config.lua @@ -42,8 +42,10 @@ local M = {} --- ClaudeCodeKeymaps class for keymap configuration -- @table ClaudeCodeKeymaps -- @field toggle ClaudeCodeKeymapsToggle Keymaps for toggling Claude Code --- @field window_navigation boolean Enable window navigation keymaps --- @field scrolling boolean Enable scrolling keymaps +-- @field window_navigation table|nil Window navigation keymaps +-- @field window_navigation.enabled boolean Enable window navigation keymaps +-- @field scrolling table|nil Scrolling keymaps +-- @field scrolling.enabled boolean Enable scrolling keymaps --- ClaudeCodeCommandVariants class for command variant configuration -- @table ClaudeCodeCommandVariants @@ -131,8 +133,18 @@ M.default_config = { verbose = 'cV', -- Normal mode keymap for Claude Code with verbose flag }, }, - window_navigation = true, -- Enable window navigation keymaps () - scrolling = true, -- Enable scrolling keymaps () for page up/down + window_navigation = { + enabled = true, -- Enable window navigation keymaps + left = '', -- Move to left window + down = '', -- Move to down window + up = '', -- Move to up window + right = '', -- Move to right window + }, + scrolling = { + enabled = true, -- Enable scrolling keymaps + page_down = '', -- Scroll down one page + page_up = '', -- Scroll up one page + }, }, } @@ -351,12 +363,44 @@ local function validate_keymaps_config(keymaps) end end - if type(keymaps.window_navigation) ~= 'boolean' then - return false, 'keymaps.window_navigation must be a boolean' + if type(keymaps.window_navigation) ~= 'table' then + return false, 'keymaps.window_navigation must be a table' + end + + if type(keymaps.window_navigation.enabled) ~= 'boolean' then + return false, 'keymaps.window_navigation.enabled must be a table' + end + + if type(keymaps.window_navigation.left) ~= 'string' then + return false, 'keymaps.window_navigation.left must be a string' + end + + if type(keymaps.window_navigation.down) ~= 'string' then + return false, 'keymaps.window_navigation.down must be a string' + end + + if type(keymaps.window_navigation.up) ~= 'string' then + return false, 'keymaps.window_navigation.up must be a string' + end + + if type(keymaps.window_navigation.right) ~= 'string' then + return false, 'keymaps.window_navigation.right must be a string' + end + + if type(keymaps.scrolling) ~= 'table' then + return false, 'keymaps.scrolling must be a btable' + end + + if type(keymaps.scrolling.enabled) ~= 'boolean' then + return false, 'keymaps.scrolling.enabled must be a boolean' + end + + if type(keymaps.scrolling.page_down) ~= 'string' then + return false, 'keymaps.scrolling.page_down must be a string' end - if type(keymaps.scrolling) ~= 'boolean' then - return false, 'keymaps.scrolling must be a boolean' + if type(keymaps.scrolling.page_up) ~= 'string' then + return false, 'keymaps.scrolling.page_up must be a string' end return true, nil diff --git a/lua/claude-code/keymaps.lua b/lua/claude-code/keymaps.lua index 5441bd1..f9caf89 100644 --- a/lua/claude-code/keymaps.lua +++ b/lua/claude-code/keymaps.lua @@ -109,33 +109,33 @@ function M.setup_terminal_navigation(claude_code, config) ) -- Window navigation keymaps - if config.keymaps.window_navigation then + if config.keymaps.window_navigation.enabled then -- Window navigation keymaps with special handling to force insert mode in the target window vim.api.nvim_buf_set_keymap( buf, 't', - '', + config.keymaps.window_navigation.left, [[h:lua require("claude-code").force_insert_mode()]], { noremap = true, silent = true, desc = 'Window: move left' } ) vim.api.nvim_buf_set_keymap( buf, 't', - '', + config.keymaps.window_navigation.down, [[j:lua require("claude-code").force_insert_mode()]], { noremap = true, silent = true, desc = 'Window: move down' } ) vim.api.nvim_buf_set_keymap( buf, 't', - '', + config.keymaps.window_navigation.up, [[k:lua require("claude-code").force_insert_mode()]], { noremap = true, silent = true, desc = 'Window: move up' } ) vim.api.nvim_buf_set_keymap( buf, 't', - '', + config.keymaps.window_navigation.right, [[l:lua require("claude-code").force_insert_mode()]], { noremap = true, silent = true, desc = 'Window: move right' } ) @@ -144,46 +144,46 @@ function M.setup_terminal_navigation(claude_code, config) vim.api.nvim_buf_set_keymap( buf, 'n', - '', + config.keymaps.window_navigation.left, [[h:lua require("claude-code").force_insert_mode()]], { noremap = true, silent = true, desc = 'Window: move left' } ) vim.api.nvim_buf_set_keymap( buf, 'n', - '', + config.keymaps.window_navigation.down, [[j:lua require("claude-code").force_insert_mode()]], { noremap = true, silent = true, desc = 'Window: move down' } ) vim.api.nvim_buf_set_keymap( buf, 'n', - '', + config.keymaps.window_navigation.up, [[k:lua require("claude-code").force_insert_mode()]], { noremap = true, silent = true, desc = 'Window: move up' } ) vim.api.nvim_buf_set_keymap( buf, 'n', - '', + config.keymaps.window_navigation.right, [[l:lua require("claude-code").force_insert_mode()]], { noremap = true, silent = true, desc = 'Window: move right' } ) end -- Add scrolling keymaps - if config.keymaps.scrolling then + if config.keymaps.scrolling.enabled then vim.api.nvim_buf_set_keymap( buf, 't', - '', + config.keymaps.scrolling.page_down, [[i]], { noremap = true, silent = true, desc = 'Scroll full page down' } ) vim.api.nvim_buf_set_keymap( buf, 't', - '', + config.keymaps.scrolling.page_up, [[i]], { noremap = true, silent = true, desc = 'Scroll full page up' } ) diff --git a/tests/spec/config_validation_spec.lua b/tests/spec/config_validation_spec.lua index f1e7188..7c563e7 100644 --- a/tests/spec/config_validation_spec.lua +++ b/tests/spec/config_validation_spec.lua @@ -83,7 +83,7 @@ describe('config validation', function() local result = config.parse_config(invalid_config, true) -- silent mode assert.are.equal(config.default_config.window.position, result.window.position) - -- Ensure invalid border doesn't bleed through + -- Ensure invalid border doesn't bleed through assert.are.not_equal('invalid', result.window.float.border) assert.are.equal(config.default_config.window.float.border, result.window.float.border) end) @@ -147,17 +147,17 @@ describe('config validation', function() assert.are.equal(config.default_config.keymaps.toggle.normal, result3.keymaps.toggle.normal) end) - it('should validate keymaps.window_navigation must be a boolean', function() + it('should validate keymaps.window_navigation.enabled must be a boolean', function() -- Simplify this test to match others local invalid_config = vim.deepcopy(config.default_config) - invalid_config.keymaps.window_navigation = 'enabled' -- String instead of boolean + invalid_config.keymaps.window_navigation.enabled = 'enabled' -- String instead of boolean -- Use silent mode to avoid pollution local result = config.parse_config(invalid_config, true) assert.are.equal( - config.default_config.keymaps.window_navigation, - result.keymaps.window_navigation + config.default_config.keymaps.window_navigation.enabled, + result.keymaps.window_navigation.enabled ) end) end) From b32bd398048dc25a2015ce262380ba5c478724a1 Mon Sep 17 00:00:00 2001 From: Theo Brigitte Date: Tue, 30 Sep 2025 20:58:08 +0200 Subject: [PATCH 2/3] =?UTF-8?q?address=20the=20rabbit=20reviews=20?= =?UTF-8?q?=F0=9F=A5=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/claude-code/config.lua | 12 ++++++------ lua/claude-code/keymaps.lua | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lua/claude-code/config.lua b/lua/claude-code/config.lua index 15be871..69cb4b8 100644 --- a/lua/claude-code/config.lua +++ b/lua/claude-code/config.lua @@ -134,16 +134,16 @@ M.default_config = { }, }, window_navigation = { - enabled = true, -- Enable window navigation keymaps - left = '', -- Move to left window - down = '', -- Move to down window - up = '', -- Move to up window + enabled = true, -- Enable window navigation keymaps + left = '', -- Move to left window + down = '', -- Move to down window + up = '', -- Move to up window right = '', -- Move to right window }, scrolling = { enabled = true, -- Enable scrolling keymaps page_down = '', -- Scroll down one page - page_up = '', -- Scroll up one page + page_up = '', -- Scroll up one page }, }, } @@ -368,7 +368,7 @@ local function validate_keymaps_config(keymaps) end if type(keymaps.window_navigation.enabled) ~= 'boolean' then - return false, 'keymaps.window_navigation.enabled must be a table' + return false, 'keymaps.window_navigation.enabled boolean' end if type(keymaps.window_navigation.left) ~= 'string' then diff --git a/lua/claude-code/keymaps.lua b/lua/claude-code/keymaps.lua index f9caf89..383ee3f 100644 --- a/lua/claude-code/keymaps.lua +++ b/lua/claude-code/keymaps.lua @@ -165,7 +165,7 @@ function M.setup_terminal_navigation(claude_code, config) vim.api.nvim_buf_set_keymap( buf, 'n', - config.keymaps.window_navigation.right, + config.keymaps.window_navigation.right, [[l:lua require("claude-code").force_insert_mode()]], { noremap = true, silent = true, desc = 'Window: move right' } ) From b7d997176c4e40b132aa294dc632614d5bc0d387 Mon Sep 17 00:00:00 2001 From: Theo Brigitte Date: Tue, 30 Sep 2025 21:46:40 +0200 Subject: [PATCH 3/3] fix typo --- lua/claude-code/config.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/claude-code/config.lua b/lua/claude-code/config.lua index 69cb4b8..9b27c99 100644 --- a/lua/claude-code/config.lua +++ b/lua/claude-code/config.lua @@ -388,7 +388,7 @@ local function validate_keymaps_config(keymaps) end if type(keymaps.scrolling) ~= 'table' then - return false, 'keymaps.scrolling must be a btable' + return false, 'keymaps.scrolling must be a table' end if type(keymaps.scrolling.enabled) ~= 'boolean' then