Skip to content

Commit

Permalink
fix(windows): safely get window sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
rcarriga committed Aug 3, 2021
1 parent a474089 commit 70c7b52
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lua/dapui/windows/layout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ function WindowLayout:_total_size()
return total_size
end

function WindowLayout:_area_size()
for _, win in pairs(self.open_wins) do
local success, area_size = pcall(self.get_area_size, win)
if success then
return area_size
end
end
return 0
end

function WindowLayout:resize()
if not self:is_open() then
return
Expand All @@ -75,14 +85,20 @@ function WindowLayout:update_sizes()
if not self:is_open() then
return
end
self.area_state.size = self.get_area_size(self.open_wins[1])
local area_size = self:_area_size()
if area_size == 0 then
return
end
self.area_state.size = area_size
local total_size = self:_total_size()
for i, win_state in ipairs(self.win_states) do
local win = self.open_wins[i]
local win_exists, _ = pcall(api.nvim_win_get_buf, win)
if win_exists then
local current_size = self.get_win_size(self.open_wins[i])
win_state.size = current_size / total_size
local success, current_size = pcall(self.get_win_size, self.open_wins[i])
if success then
win_state.size = current_size / total_size
end
end
end
end
Expand Down

0 comments on commit 70c7b52

Please sign in to comment.