From e9474bb1be73bcbcb16131e472dd0c6c689b2d36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Fl=C3=BCgge?= Date: Tue, 28 May 2024 01:31:03 +0200 Subject: [PATCH] fix: allow to switch back to day selection --- lua/orgmode/objects/calendar.lua | 53 +++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/lua/orgmode/objects/calendar.lua b/lua/orgmode/objects/calendar.lua index 0fbebc9ae..452707cb7 100644 --- a/lua/orgmode/objects/calendar.lua +++ b/lua/orgmode/objects/calendar.lua @@ -204,7 +204,11 @@ function Calendar:render() -- FIXME this line is currently not shown because of a bug. if self:has_time() then - table.insert(content, ' [t] - enter time [T] - clear time') + if self.select_state == SelState.DAY then + table.insert(content, ' [t] - enter time [T] - clear time') + else + table.insert(content, ' [d] - enter time [T] - clear time') + end else table.insert(content, ' [t] - enter time') end @@ -281,6 +285,32 @@ function Calendar:render_time() return l_pad .. hour_str .. ':' .. min_str .. r_pad end +function Calendar:rerender_time() + vim.api.nvim_set_option_value('modifiable', true, { buf = self.buf }) + vim.api.nvim_buf_set_lines(self.buf, 8, 9, true, { self:render_time() }) + if self:has_time() then + local map_opts = { buffer = self.buf, silent = true, nowait = true } + vim.keymap.set('n', 'T', function() + self:clear_time() + end, map_opts) + vim.keymap.set('n', 'd', function() + self:set_day() + end, map_opts) + if self.select_state == SelState.DAY then + vim.api.nvim_buf_set_lines(self.buf, 13, 14, true, { ' [t] - select day [T] - clear time' }) + else + vim.api.nvim_buf_set_lines(self.buf, 13, 14, true, { ' [d] - select day [T] - clear time' }) + end + vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Normal', 8, 0, -1) + vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', 13, 0, -1) + else + vim.api.nvim_buf_set_lines(self.buf, 13, 14, true, { ' [t] - enter time' }) + vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', 8, 0, -1) + vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', 13, 0, -1) + end + vim.api.nvim_set_option_value('modifiable', false, { buf = self.buf }) +end + function Calendar:has_time() return not self.date.date_only end @@ -552,28 +582,15 @@ function Calendar:set_time() self:set_sel_hour() end -function Calendar:rerender_time() - vim.api.nvim_set_option_value('modifiable', true, { buf = self.buf }) - vim.api.nvim_buf_set_lines(self.buf, 8, 9, true, { self:render_time() }) - if self:has_time() then - vim.keymap.set('n', 'T', function() - self:clear_time() - end, { buffer = self.buf, silent = true, nowait = true }) - vim.api.nvim_buf_set_lines(self.buf, 13, 14, true, { ' [t] - enter time [T] - clear time' }) - vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Normal', 8, 0, -1) - vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', 13, 0, -1) - else - vim.api.nvim_buf_set_lines(self.buf, 13, 14, true, { ' [t] - enter time' }) - vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', 8, 0, -1) - vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', 13, 0, -1) - end - vim.api.nvim_set_option_value('modifiable', false, { buf = self.buf }) +function Calendar:set_day() + self:set_sel_day() + self:rerender_time() end function Calendar:clear_time() self.date = self.date:set({ hour = 0, min = 0, date_only = true }) - self:rerender_time() self:set_sel_day() + self:rerender_time() end function Calendar:set_sel_hour()