Skip to content

Commit 4ec3acb

Browse files
committed
Merge branch 'main' into mini.files_support_touch-ups
Change-Id: I582d5989a859be1ef7578e14c66851f06c267d70 Signed-off-by: Thomas Kosiewski <[email protected]>
2 parents 1af2474 + ee1f537 commit 4ec3acb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1130
-908
lines changed

.luarc.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

CLAUDE.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,32 @@ Enable detailed authentication logging by setting:
253253

254254
```lua
255255
require("claudecode").setup({
256-
log_level = "debug" -- Shows auth token generation, validation, and failures
256+
log_level = "debug", -- Shows auth token generation, validation, and failures
257+
diff_opts = {
258+
keep_terminal_focus = true, -- If true, moves focus back to terminal after diff opens
259+
},
260+
})
261+
```
262+
263+
### Configuration Options
264+
265+
#### Diff Options
266+
267+
The `diff_opts` configuration allows you to customize diff behavior:
268+
269+
- `keep_terminal_focus` (boolean, default: `false`) - When enabled, keeps focus in the Claude Code terminal when a diff opens instead of moving focus to the diff buffer. This allows you to continue using terminal keybindings like `<CR>` for accepting/rejecting diffs without accidentally triggering other mappings.
270+
271+
**Example use case**: If you frequently use `<CR>` or arrow keys in the Claude Code terminal to accept/reject diffs, enable this option to prevent focus from moving to the diff buffer where `<CR>` might trigger unintended actions.
272+
273+
```lua
274+
require("claudecode").setup({
275+
diff_opts = {
276+
keep_terminal_focus = true, -- If true, moves focus back to terminal after diff opens
277+
auto_close_on_accept = true,
278+
show_diff_stats = true,
279+
vertical_split = true,
280+
open_in_current_tab = true,
281+
},
257282
})
258283
```
259284

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ For deep technical details, see [ARCHITECTURE.md](./ARCHITECTURE.md).
267267
auto_close_on_accept = true,
268268
vertical_split = true,
269269
open_in_current_tab = true,
270+
keep_terminal_focus = false, -- If true, moves focus back to terminal after diff opens
270271
},
271272
},
272273
keys = {

dev-config.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ return {
1818
{ "<leader>am", "<cmd>ClaudeCodeSelectModel<cr>", desc = "Select Claude model" },
1919

2020
-- Context sending
21-
{ "<leader>ab", "<cmd>ClaudeCodeAdd %<cr>", desc = "Add current buffer" },
21+
{ "<leader>as", "<cmd>ClaudeCodeAdd %<cr>", mode = "n", desc = "Add current buffer" },
2222
{ "<leader>as", "<cmd>ClaudeCodeSend<cr>", mode = "v", desc = "Send to Claude" },
2323
{
2424
"<leader>as",
@@ -62,6 +62,7 @@ return {
6262
-- show_diff_stats = true, -- Show diff statistics
6363
-- vertical_split = true, -- Use vertical split for diffs
6464
-- open_in_current_tab = true, -- Open diffs in current tab vs new tab
65+
-- keep_terminal_focus = false, -- If true, moves focus back to terminal after diff opens
6566
-- },
6667

6768
-- Terminal Configuration

fixtures/nvim-tree/lazy-lock.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" },
3-
"nvim-tree.lua": { "branch": "master", "commit": "65bae449224b8a3bc149471b96587b23b13a9946" },
4-
"nvim-web-devicons": { "branch": "master", "commit": "4a8369f4c78ef6f6f895f0cec349e48f74330574" },
3+
"nvim-tree.lua": { "branch": "master", "commit": "0a7fcdf3f8ba208f4260988a198c77ec11748339" },
4+
"nvim-web-devicons": { "branch": "master", "commit": "3362099de3368aa620a8105b19ed04c2053e38c0" },
55
"tokyonight.nvim": { "branch": "main", "commit": "057ef5d260c1931f1dffd0f052c685dcd14100a3" }
66
}

lua/claudecode/config.lua

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,41 @@
1+
---@brief [[
12
--- Manages configuration for the Claude Code Neovim integration.
2-
-- Provides default settings, validation, and application of user-defined configurations.
3+
--- Provides default settings, validation, and application of user-defined configurations.
4+
---@brief ]]
5+
---@module 'claudecode.config'
6+
37
local M = {}
48

9+
-- Types (authoritative for configuration shape):
10+
---@class ClaudeCode.DiffOptions
11+
---@field auto_close_on_accept boolean
12+
---@field show_diff_stats boolean
13+
---@field vertical_split boolean
14+
---@field open_in_current_tab boolean
15+
---@field keep_terminal_focus boolean
16+
17+
---@class ClaudeCode.ModelOption
18+
---@field name string
19+
---@field value string
20+
21+
---@alias ClaudeCode.LogLevel "trace"|"debug"|"info"|"warn"|"error"
22+
23+
---@class ClaudeCode.Config
24+
---@field port_range {min: integer, max: integer}
25+
---@field auto_start boolean
26+
---@field terminal_cmd string|nil
27+
---@field env table<string, string>
28+
---@field log_level ClaudeCode.LogLevel
29+
---@field track_selection boolean
30+
---@field visual_demotion_delay_ms number
31+
---@field connection_wait_delay number
32+
---@field connection_timeout number
33+
---@field queue_timeout number
34+
---@field diff_opts ClaudeCode.DiffOptions
35+
---@field models ClaudeCode.ModelOption[]
36+
---@field disable_broadcast_debouncing? boolean
37+
---@field enable_broadcast_debouncing_in_tests? boolean
38+
---@field terminal TerminalConfig|nil
539
M.defaults = {
640
port_range = { min = 10000, max = 65535 },
741
auto_start = true,
@@ -18,17 +52,19 @@ M.defaults = {
1852
show_diff_stats = true,
1953
vertical_split = true,
2054
open_in_current_tab = true, -- Use current tab instead of creating new tab
55+
keep_terminal_focus = false, -- If true, moves focus back to terminal after diff opens
2156
},
2257
models = {
2358
{ name = "Claude Opus 4 (Latest)", value = "opus" },
2459
{ name = "Claude Sonnet 4 (Latest)", value = "sonnet" },
2560
},
61+
terminal = nil, -- Will be lazy-loaded to avoid circular dependency
2662
}
2763

28-
--- Validates the provided configuration table.
29-
-- @param config table The configuration table to validate.
30-
-- @return boolean true if the configuration is valid.
31-
-- @error string if any configuration option is invalid.
64+
---Validates the provided configuration table.
65+
---Throws an error if any validation fails.
66+
---@param config table The configuration table to validate.
67+
---@return boolean true if the configuration is valid.
3268
function M.validate(config)
3369
assert(
3470
type(config.port_range) == "table"
@@ -78,6 +114,7 @@ function M.validate(config)
78114
assert(type(config.diff_opts.show_diff_stats) == "boolean", "diff_opts.show_diff_stats must be a boolean")
79115
assert(type(config.diff_opts.vertical_split) == "boolean", "diff_opts.vertical_split must be a boolean")
80116
assert(type(config.diff_opts.open_in_current_tab) == "boolean", "diff_opts.open_in_current_tab must be a boolean")
117+
assert(type(config.diff_opts.keep_terminal_focus) == "boolean", "diff_opts.keep_terminal_focus must be a boolean")
81118

82119
-- Validate env
83120
assert(type(config.env) == "table", "env must be a table")
@@ -95,17 +132,34 @@ function M.validate(config)
95132
assert(type(model.name) == "string" and model.name ~= "", "models[" .. i .. "].name must be a non-empty string")
96133
assert(type(model.value) == "string" and model.value ~= "", "models[" .. i .. "].value must be a non-empty string")
97134
end
135+
98136
return true
99137
end
100138

101-
--- Applies user configuration on top of default settings and validates the result.
102-
-- @param user_config table|nil The user-provided configuration table.
103-
-- @return table The final, validated configuration table.
139+
---Applies user configuration on top of default settings and validates the result.
140+
---@param user_config table|nil The user-provided configuration table.
141+
---@return ClaudeCode.Config config The final, validated configuration table.
104142
function M.apply(user_config)
105143
local config = vim.deepcopy(M.defaults)
106144

145+
-- Lazy-load terminal defaults to avoid circular dependency
146+
if config.terminal == nil then
147+
local terminal_ok, terminal_module = pcall(require, "claudecode.terminal")
148+
if terminal_ok and terminal_module.defaults then
149+
config.terminal = terminal_module.defaults
150+
end
151+
end
152+
107153
if user_config then
108-
config = vim.tbl_deep_extend("force", config, user_config)
154+
-- Use vim.tbl_deep_extend if available, otherwise simple merge
155+
if vim.tbl_deep_extend then
156+
config = vim.tbl_deep_extend("force", config, user_config)
157+
else
158+
-- Simple fallback for testing environment
159+
for k, v in pairs(user_config) do
160+
config[k] = v
161+
end
162+
end
109163
end
110164

111165
M.validate(config)

0 commit comments

Comments
 (0)