feat: dynamic main with - #4
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for configuring the “main” window width dynamically (via a function) and updates the side-window sizing logic to use the resolved width.
Changes:
- Extend
Config/ConfigOptionstyping to allowmain.widthto benumberorfun(): number. - Introduce
get_main_width()helper and route width calculations/comparisons through it. - Update side-window resizing logic to use the resolved main width consistently.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Agent-Logs-Url: https://github.com/sand4rt/zen.nvim/sessions/776df3ec-ea1f-48b9-96ac-c13025ddf517 Co-authored-by: sand4rt <17591696+sand4rt@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| vim.api.nvim_win_set_width(win_id, math.floor((vim.o.columns - get_main_width()) / 2)) | ||
| vim.api.nvim_set_option_value("winfixwidth", true, { scope = "local", win = win_id }) | ||
| vim.api.nvim_set_option_value("winfixbuf", true, { scope = "local", win = win_id }) | ||
| vim.api.nvim_set_option_value("cursorline", false, { scope = "local", win = win_id }) |
There was a problem hiding this comment.
Because opts.main.width can now be a function, evaluating get_main_width() multiple times across a single operation can yield inconsistent results (e.g., the caller checks vim.o.columns <= get_main_width() and then create_window() recomputes a different width). That can produce negative/invalid side widths in nvim_win_set_width. Consider computing local main_width = get_main_width() once in the autocmd callback and passing it into create_window() (or into the width calculation) so the check and the arithmetic use the same value.
| local left = vim.api.nvim_win_is_valid(get_side_buffer("left")) | ||
| if left then | ||
| vim.api.nvim_win_set_width(get_side_buffer("left"), new_width) |
There was a problem hiding this comment.
resize_side_buffers() recomputes get_main_width() internally. With a functional main.width, callers may already have checked vim.o.columns <= get_main_width() using a different value, leading to negative/invalid new_width. To keep behavior consistent, consider passing the resolved main_width into resize_side_buffers(main_width) (and using that value throughout the calling callback) rather than calling get_main_width() again here.
No description provided.