Skip to content

Commit 1460cbe

Browse files
committed
feat: persist window width across hide/restore
Save user-adjusted window width ratio when hiding and restore it when restoring hidden windows.
1 parent dffa3f3 commit 1460cbe

4 files changed

Lines changed: 20 additions & 6 deletions

File tree

lua/opencode/state.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
---@field api_client OpencodeApiClient
5959
---@field event_manager EventManager|nil
6060
---@field pre_zoom_width integer|nil
61+
---@field last_window_width_ratio number|nil
6162
---@field required_version string
6263
---@field opencode_cli_version string|nil
6364
---@field current_cwd string|nil

lua/opencode/ui/input_window.lua

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ local function apply_dimensions(windows, height)
5858
return
5959
end
6060

61-
local total_width = vim.api.nvim_get_option_value('columns', {})
62-
local width_ratio = state.pre_zoom_width and config.ui.zoom_width or config.ui.window_width
63-
local width = math.floor(total_width * width_ratio)
64-
65-
pcall(vim.api.nvim_win_set_config, windows.input_win, { width = width, height = height })
61+
pcall(vim.api.nvim_win_set_config, windows.input_win, { height = height })
6662
end
6763

6864
function M.create_buf()

lua/opencode/ui/output_window.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,17 @@ function M.update_dimensions(windows)
133133
return
134134
end
135135
local total_width = vim.api.nvim_get_option_value('columns', {})
136-
local width_ratio = state.pre_zoom_width and config.ui.zoom_width or config.ui.window_width
136+
137+
local width_ratio
138+
if windows.saved_width_ratio then
139+
width_ratio = windows.saved_width_ratio
140+
windows.saved_width_ratio = nil
141+
elseif state.pre_zoom_width then
142+
width_ratio = config.ui.zoom_width
143+
else
144+
width_ratio = config.ui.window_width
145+
end
146+
137147
local width = math.floor(total_width * width_ratio)
138148

139149
vim.api.nvim_win_set_config(windows.output_win, { width = width })

lua/opencode/ui/ui.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ function M.hide_visible_windows(windows)
134134
end
135135

136136
local snapshot = capture_hidden_snapshot(windows)
137+
138+
local total_cols = vim.o.columns
139+
local current_width = vim.api.nvim_win_get_width(windows.output_win)
140+
state.last_window_width_ratio = current_width / total_cols
141+
137142
state.clear_hidden_window_state()
138143

139144
prepare_window_close()
@@ -227,6 +232,7 @@ function M.restore_hidden_windows()
227232
windows.output_win = win_ids.output_win
228233
windows.footer_win = nil
229234
windows.output_was_at_bottom = hidden.output_was_at_bottom == true
235+
windows.saved_width_ratio = state.last_window_width_ratio
230236

231237
state.set_cursor_position('input', hidden.input_cursor)
232238
state.set_cursor_position('output', hidden.output_cursor)
@@ -349,6 +355,7 @@ function M.create_windows()
349355

350356
windows.input_win = win_ids.input_win
351357
windows.output_win = win_ids.output_win
358+
windows.saved_width_ratio = state.last_window_width_ratio
352359

353360
input_window.setup(windows)
354361
output_window.setup(windows)

0 commit comments

Comments
 (0)