Skip to content

Commit

Permalink
fix: maintain cmdheight
Browse files Browse the repository at this point in the history
See #108
  • Loading branch information
rcarriga committed Jul 23, 2022
1 parent d33b905 commit b7b7144
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 66 deletions.
140 changes: 77 additions & 63 deletions lua/dapui/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,35 @@ function dapui.setup(user_config)
end)
end

local function keep_cmdheight(cb)
local cmd_height = vim.o.cmdheight

cb()

vim.o.cmdheight = cmd_height
end

---Close one or all of the window layouts
---@param opts table
---@field layout number|nil: Index of layout in config
function dapui.close(opts)
opts = opts or {}
if type(opts) == "number" then
opts = { layout = opts }
end
local layout = opts.layout
keep_cmdheight(function()
opts = opts or {}
if type(opts) == "number" then
opts = { layout = opts }
end
local layout = opts.layout

for _, win_layout in ipairs(windows.layouts) do
win_layout:update_sizes()
end
for i, win_layout in ipairs(windows.layouts) do
if not layout or layout == i then
for _, win_layout in ipairs(windows.layouts) do
win_layout:update_sizes()
win_layout:close()
end
end
for i, win_layout in ipairs(windows.layouts) do
if not layout or layout == i then
win_layout:update_sizes()
win_layout:close()
end
end
end)
end

---@generic T
Expand All @@ -182,80 +192,84 @@ end
---@field layout number|nil: Index of layout in config
---@field reset boolean: Reset windows to original size
function dapui.open(opts)
opts = opts or {}
if type(opts) == "number" then
opts = { layout = opts }
end
local layout = opts.layout
keep_cmdheight(function()
opts = opts or {}
if type(opts) == "number" then
opts = { layout = opts }
end
local layout = opts.layout

for _, win_layout in ipairs(windows.layouts) do
win_layout:update_sizes()
end
local closed = {}
if layout then
for i = 1, (layout and layout - 1) or #windows.layouts, 1 do
if windows.layouts[i]:is_open() then
closed[#closed + 1] = i
windows.layouts[i]:close()
for _, win_layout in ipairs(windows.layouts) do
win_layout:update_sizes()
end
local closed = {}
if layout then
for i = 1, (layout and layout - 1) or #windows.layouts, 1 do
if windows.layouts[i]:is_open() then
closed[#closed + 1] = i
windows.layouts[i]:close()
end
end
end
end

for i, win_layout in reverse(windows.layouts) do
if not layout or layout == i then
win_layout:open()
for i, win_layout in reverse(windows.layouts) do
if not layout or layout == i then
win_layout:open()
end
end
end

if #closed > 0 then
for _, i in ipairs(closed) do
windows.layouts[i]:open()
if #closed > 0 then
for _, i in ipairs(closed) do
windows.layouts[i]:open()
end
end
end

for _, win_layout in ipairs(windows.layouts) do
win_layout:resize(opts)
end
for _, win_layout in ipairs(windows.layouts) do
win_layout:resize(opts)
end
end)
end

---Toggle one or all of the window layouts.
---@param opts table
---@field layout number|nil: Index of layout in config
---@field reset boolean: Reset windows to original size
function dapui.toggle(opts)
opts = opts or {}
if type(opts) == "number" then
opts = { layout = opts }
end
local layout = opts.layout
keep_cmdheight(function()
opts = opts or {}
if type(opts) == "number" then
opts = { layout = opts }
end
local layout = opts.layout

for _, win_layout in reverse(windows.layouts) do
win_layout:update_sizes()
end
for _, win_layout in reverse(windows.layouts) do
win_layout:update_sizes()
end

local closed = {}
if layout then
for i = 1, (layout and layout - 1) or #windows.layouts, 1 do
if windows.layouts[i]:is_open() then
closed[#closed + 1] = i
windows.layouts[i]:close()
local closed = {}
if layout then
for i = 1, (layout and layout - 1) or #windows.layouts, 1 do
if windows.layouts[i]:is_open() then
closed[#closed + 1] = i
windows.layouts[i]:close()
end
end
end
end

for i, win_layout in reverse(windows.layouts) do
if not layout or layout == i then
win_layout:toggle()
for i, win_layout in reverse(windows.layouts) do
if not layout or layout == i then
win_layout:toggle()
end
end
end

for _, i in reverse(closed) do
windows.layouts[i]:open()
end
for _, i in reverse(closed) do
windows.layouts[i]:open()
end

for _, win_layout in ipairs(windows.layouts) do
win_layout:resize(opts)
end
for _, win_layout in ipairs(windows.layouts) do
win_layout:resize(opts)
end
end)
end

return dapui
5 changes: 2 additions & 3 deletions lua/dapui/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ function M.jump_to_frame(frame, session, set_frame)
column = 1
end

local bufnr = vim.uri_to_bufnr(
M.is_uri(path) and path or vim.uri_from_fname(vim.fn.fnamemodify(path, ":p"))
)
local bufnr =
vim.uri_to_bufnr(M.is_uri(path) and path or vim.uri_from_fname(vim.fn.fnamemodify(path, ":p")))
vim.fn.bufload(bufnr)
M.open_buf(bufnr, line, column)
end
Expand Down

0 comments on commit b7b7144

Please sign in to comment.