diff --git a/lua/orgmode/objects/calendar.lua b/lua/orgmode/objects/calendar.lua index c0d0cba9..4ae50c7d 100644 --- a/lua/orgmode/objects/calendar.lua +++ b/lua/orgmode/objects/calendar.lua @@ -57,21 +57,23 @@ local y_offset = 2 -- one border cell and one padding cell ---@return OrgPromise function Calendar:open() - local opts = { - relative = 'editor', - width = width, - height = height, - style = 'minimal', - border = config.win_border, - row = vim.o.lines / 2 - (y_offset + height) / 2, - col = vim.o.columns / 2 - (x_offset + width) / 2, - title = self.title or 'Calendar', - title_pos = 'center', - } + local get_window_opts = function() + return { + relative = 'editor', + width = width, + height = height, + style = 'minimal', + border = config.win_border, + row = vim.o.lines / 2 - (y_offset + height) / 2, + col = vim.o.columns / 2 - (x_offset + width) / 2, + title = self.title or 'Calendar', + title_pos = 'center', + } + end self.buf = vim.api.nvim_create_buf(false, true) vim.api.nvim_buf_set_name(self.buf, 'orgcalendar') - self.win = vim.api.nvim_open_win(self.buf, true, opts) + self.win = vim.api.nvim_open_win(self.buf, true, get_window_opts()) local calendar_augroup = vim.api.nvim_create_augroup('org_calendar', { clear = true }) vim.api.nvim_create_autocmd('BufWipeout', { @@ -83,6 +85,16 @@ function Calendar:open() once = true, }) + vim.api.nvim_create_autocmd('VimResized', { + buffer = self.buf, + group = calendar_augroup, + callback = function() + if self.win then + vim.api.nvim_win_set_config(self.win, get_window_opts()) + end + end, + }) + self:render() vim.api.nvim_set_option_value('winhl', 'Normal:Normal', { win = self.win })