Skip to content

Commit 3e61767

Browse files
fix(float_element): auto detect size for centered floating element (#411)
1 parent 63374a3 commit 3e61767

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

lua/dapui/windows/float.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ function Float:listen(event, callback)
5353
self.listeners[event][#self.listeners[event] + 1] = callback
5454
end
5555

56-
function Float:resize(width, height)
57-
local opts = create_opts(width, height, self.position)
56+
function Float:resize(width, height, position)
57+
if position == nil then
58+
position = self.position
59+
end
60+
local opts = create_opts(width, height, position)
5861
api.nvim_win_set_config(self.win_id, opts)
5962
end
6063

lua/dapui/windows/init.lua

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,6 @@ function M.open_float(name, element, position, settings)
123123
float_windows[name]:jump_to()
124124
return float_windows[name]
125125
end
126-
if settings.position == "center" then
127-
local screen_w = vim.opt.columns:get()
128-
local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get()
129-
position.line = (screen_h - settings.height) / 2
130-
position.col = (screen_w - settings.width) / 2
131-
end
132126
local buf = element.buffer()
133127
local float_win = require("dapui.windows.float").open_float({
134128
height = settings.height or 1,
@@ -156,10 +150,17 @@ function M.open_float(name, element, position, settings)
156150
end
157151
end
158152

153+
if settings.position == "center" then
154+
local screen_w = vim.opt.columns:get()
155+
local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get()
156+
position.line = (screen_h - height) / 2
157+
position.col = (screen_w - width) / 2
158+
end
159+
159160
if width <= 0 or height <= 0 then
160161
return
161162
end
162-
float_win:resize(width, height)
163+
float_win:resize(width, height, position)
163164
end
164165

165166
nio.api.nvim_buf_attach(buf, true, {

0 commit comments

Comments
 (0)