Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c2603ce

Browse files
committed
feat: add dimension fallback and position clamping
- Add nil check for dimensions with 80% default fallback - Clamp calculated positions to ensure window stays visible on screen - Prevents floating windows from appearing partially off-screen - Makes configuration more forgiving with sensible defaults Addresses CodeRabbitAI feedback on floating window PR
1 parent a3fb884 commit c2603ce

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

lua/claude-code/terminal.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ end
3636
--- @return number Calculated dimension
3737
--- @private
3838
local function calculate_float_dimension(value, max_value)
39-
if type(value) == 'string' and value:match('^%d+%%$') then
39+
if value == nil then
40+
return math.floor(max_value * 0.8) -- Default to 80% if not specified
41+
elseif type(value) == 'string' and value:match('^%d+%%$') then
4042
local percentage = tonumber(value:match('^(%d+)%%$'))
4143
return math.floor(max_value * percentage / 100)
4244
end
@@ -50,13 +52,17 @@ end
5052
--- @return number Calculated position
5153
--- @private
5254
local function calculate_float_position(value, window_size, max_value)
55+
local pos
5356
if value == 'center' then
54-
return math.floor((max_value - window_size) / 2)
57+
pos = math.floor((max_value - window_size) / 2)
5558
elseif type(value) == 'string' and value:match('^%d+%%$') then
5659
local percentage = tonumber(value:match('^(%d+)%%$'))
57-
return math.floor(max_value * percentage / 100)
60+
pos = math.floor(max_value * percentage / 100)
61+
else
62+
pos = value or 0
5863
end
59-
return value or 0
64+
-- Clamp position to ensure window is visible
65+
return math.max(0, math.min(pos, max_value - window_size))
6066
end
6167

6268
--- Create a floating window for Claude Code

0 commit comments

Comments
 (0)