Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lua/opencode/ui/footer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,27 @@ function M.mounted(windows)
and vim.api.nvim_win_is_valid(windows.output_win --[[@as integer]])
end

---Set footer float visibility without unmounting it.
---The footer is chrome of the input area: input_window._hide hides it
---together with the input window, _show restores it.
---@param visible boolean
function M.set_visible(visible)
if not M.mounted() then
return
end
---@cast state.windows OpencodeWindowState
local ok = pcall(vim.api.nvim_win_set_config, state.windows.footer_win --[[@as integer]], {
hide = not visible,
})
if not ok then
return
end
if visible then
-- re-anchor: the output window may have resized while the footer was hidden
M.update_window(state.windows)
end
end

---@param windows table Windows table with footer_win and output_win
function M.update_window(windows)
if not M.mounted(windows) then
Expand Down
4 changes: 4 additions & 0 deletions lua/opencode/ui/input_window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@ function M._hide()
pcall(vim.api.nvim_win_close, windows.input_win, false)
windows.input_win = nil

require('opencode.ui.footer').set_visible(false)

if windows.position == 'float' then
float_layout.update(windows, false)
end
Expand Down Expand Up @@ -577,6 +579,7 @@ function M._show()
M.setup(windows)
M._hidden = false
M.focus_input()
require('opencode.ui.footer').set_visible(true)

if was_at_bottom then
vim.schedule(function()
Expand All @@ -602,6 +605,7 @@ function M._show()

-- Focus the input window
M.focus_input()
require('opencode.ui.footer').set_visible(true)

if was_at_bottom then
vim.schedule(function()
Expand Down
61 changes: 61 additions & 0 deletions tests/unit/input_window_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,67 @@ describe('input_window', function()
end)
end)

describe('footer visibility follows input window', function()
local input_buf, output_buf, input_win, output_win
local footer

before_each(function()
footer = require('opencode.ui.footer')
input_buf = vim.api.nvim_create_buf(false, true)
output_buf = vim.api.nvim_create_buf(false, true)
input_win = vim.api.nvim_open_win(input_buf, true, {
relative = 'editor',
width = 80,
height = 8,
row = 0,
col = 0,
})
output_win = vim.api.nvim_open_win(output_buf, false, {
relative = 'editor',
width = 80,
height = 8,
row = 10,
col = 0,
})

state.ui.set_windows({
input_buf = input_buf,
input_win = input_win,
output_buf = output_buf,
output_win = output_win,
footer_buf = footer.create_buf(),
})
footer.setup(state.windows)
end)

after_each(function()
footer.close()
pcall(vim.api.nvim_win_close, state.windows and state.windows.input_win or input_win, true)
pcall(vim.api.nvim_win_close, output_win, true)
pcall(vim.api.nvim_buf_delete, input_buf, { force = true })
pcall(vim.api.nvim_buf_delete, output_buf, { force = true })
state.ui.clear_windows()
state.ui.set_input_content({})
input_window._hidden = false
end)

local function footer_hidden()
return vim.api.nvim_win_get_config(state.windows.footer_win).hide == true
end

it('hides footer when input hides and restores it when input returns', function()
assert.is_false(footer_hidden())

input_window._hide()
assert.is_true(input_window.is_hidden())
assert.is_true(footer_hidden())

input_window._show()
assert.is_false(input_window.is_hidden())
assert.is_false(footer_hidden())
end)
end)

describe('_hide focus', function()
local editor_win, input_win, output_win, input_buf, output_buf

Expand Down
Loading