5757M .create_float = function (lines , opts )
5858 local window = opts .window
5959
60+ --- TODO: Remove this and remove all background dimming
6061 -- Create background window for dimming effect if enabled
6162 if opts .show_dim then
6263 M .create_background_window ()
6364 end
6465
65- local config = require (" codecompanion.config" )
66- local window_width = config .resolve_value (window .width )
67- local width = window_width and (window_width > 1 and window_width or opts .width or 85 ) or opts .width or 85
68- local window_height = config .resolve_value (window .height )
69- local height = window_height and (window_height > 1 and window_height or opts .height or 17 ) or opts .height or 17
66+ local cols = function ()
67+ return vim .o .columns
68+ end
69+ local rows = function ()
70+ return vim .o .lines
71+ end
72+
73+ if type (window .height ) == " function" then
74+ window .height = window .height ()
75+ end
76+ if type (window .width ) == " function" then
77+ window .width = window .width ()
78+ end
79+ if type (window .height ) == " string" then
80+ window .height = rows ()
81+ end
82+ if type (window .width ) == " string" then
83+ window .width = cols ()
84+ end
85+
86+ local width = window .width and (window .width > 1 and window .width or opts .width or 85 ) or opts .width or 85
87+ local height = window .height and (window .height > 1 and window .height or opts .height or 17 ) or opts .height or 17
7088
7189 local bufnr = opts .bufnr or api .nvim_create_buf (false , true )
7290
@@ -76,10 +94,10 @@ M.create_float = function(lines, opts)
7694 local row = opts .row or window .row or 10
7795 local col = opts .col or window .col or 0
7896 if row == " center" then
79- row = math.floor ((vim . o . lines - height ) / 2 - 1 ) -- Account for status line for better UX
97+ row = math.floor ((rows () - height ) / 2 - 1 ) -- Account for status line for better UX
8098 end
8199 if col == " center" then
82- col = math.floor ((vim . o . columns - width ) / 2 )
100+ col = math.floor ((cols () - width ) / 2 )
83101 end
84102
85103 local winnr = api .nvim_open_win (bufnr , true , {
@@ -293,31 +311,6 @@ function M.scroll_to_line(bufnr, line_num)
293311 end )
294312end
295313
296- --- Scroll to line and briefly highlight the edit area
297- --- @param bufnr number The buffer number
298- --- @param line_num number The line number to scroll to
299- --- @param num_lines ? number Number of lines that were changed
300- function M .scroll_and_highlight (bufnr , line_num , num_lines )
301- num_lines = num_lines or 1
302-
303- M .scroll_to_line (bufnr , line_num )
304-
305- local ns_id = api .nvim_create_namespace (" codecompanion_edit_highlight" )
306-
307- -- Highlight the edited lines
308- for i = 0 , num_lines - 1 do
309- local highlight_line = line_num + i - 1 -- Convert to 0-based
310- if highlight_line >= 0 and highlight_line < api .nvim_buf_line_count (bufnr ) then
311- api .nvim_buf_add_highlight (bufnr , ns_id , " DiffAdd" , highlight_line , 0 , - 1 )
312- end
313- end
314-
315- -- Clear highlight after a short delay
316- vim .defer_fn (function ()
317- api .nvim_buf_clear_namespace (bufnr , ns_id , 0 , - 1 )
318- end , 2000 ) -- 2 seconds
319- end
320-
321314--- @param bufnr nil | number
322315--- @return nil | number
323316M .buf_get_win = function (bufnr )
0 commit comments