Skip to content

Commit 5945634

Browse files
committed
refactor: extract focus normalization logic into shared helper
- Add normalize_focus() helper function in both snacks and native providers - Replace duplicated focus defaulting logic with consistent helper calls - Remove unused normalize_focus() from main terminal.lua file - Maintain backward compatibility by defaulting focus to true - Clean up linting warnings This addresses the Copilot feedback about duplicated focus defaulting logic across both providers and simplifies future maintenance. Change-Id: I8387f264d85a3c097081f7976bc0a34b9b52485c Signed-off-by: Thomas Kosiewski <[email protected]>
1 parent bcf7e43 commit 5945634

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lua/claudecode/terminal/native.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ local M = {}
66

77
local logger = require("claudecode.logger")
88

9+
--- Normalizes focus parameter to default to true for backward compatibility
10+
--- @param focus boolean|nil The focus parameter
11+
--- @return boolean Normalized focus value
12+
local function normalize_focus(focus)
13+
return focus == nil and true or focus
14+
end
15+
916
local bufnr = nil
1017
local winid = nil
1118
local jobid = nil
@@ -46,7 +53,7 @@ local function is_valid()
4653
end
4754

4855
local function open_terminal(cmd_string, env_table, effective_config, focus)
49-
focus = focus == nil and true or focus -- Default to true for backward compatibility
56+
focus = normalize_focus(focus)
5057

5158
if is_valid() then -- Should not happen if called correctly, but as a safeguard
5259
if focus then
@@ -262,7 +269,7 @@ end
262269
--- @param effective_config table
263270
--- @param focus boolean|nil
264271
function M.open(cmd_string, env_table, effective_config, focus)
265-
focus = focus == nil and true or focus -- Default to true for backward compatibility
272+
focus = normalize_focus(focus)
266273

267274
if is_valid() then
268275
if focus then

lua/claudecode/terminal/snacks.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,19 @@ local function setup_terminal_events(term_instance, config)
4141
end, { buf = true })
4242
end
4343

44+
--- Normalizes focus parameter to default to true for backward compatibility
45+
--- @param focus boolean|nil The focus parameter
46+
--- @return boolean Normalized focus value
47+
local function normalize_focus(focus)
48+
return focus == nil and true or focus
49+
end
50+
4451
--- @param config table
4552
--- @param env_table table
4653
--- @param focus boolean|nil
4754
--- @return table
4855
local function build_opts(config, env_table, focus)
49-
focus = focus == nil and true or focus -- Default to true for backward compatibility
56+
focus = normalize_focus(focus)
5057
return {
5158
env = env_table,
5259
start_insert = focus,
@@ -75,7 +82,7 @@ function M.open(cmd_string, env_table, config, focus)
7582
return
7683
end
7784

78-
focus = focus == nil and true or focus -- Default to true for backward compatibility
85+
focus = normalize_focus(focus)
7986

8087
if terminal and terminal:buf_valid() then
8188
if focus then

0 commit comments

Comments
 (0)