From 68ab4dc7c805db5375f3733b7f67f7400b3721e5 Mon Sep 17 00:00:00 2001 From: Andrea Date: Mon, 8 May 2023 16:39:32 +0200 Subject: [PATCH] Implemented distance (monthly view) and run make format --- lua/neorg/modules/core/ui/calendar/module.lua | 12 +++---- .../core/ui/calendar/views/monthly.lua | 35 ++++++++++++------- lua/neorg/modules/core/ui/module.lua | 4 +-- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/lua/neorg/modules/core/ui/calendar/module.lua b/lua/neorg/modules/core/ui/calendar/module.lua index c5e3ff212..553875060 100644 --- a/lua/neorg/modules/core/ui/calendar/module.lua +++ b/lua/neorg/modules/core/ui/calendar/module.lua @@ -7,7 +7,7 @@ module.setup = function() return { requires = { "core.ui", - "core.ui.calendar.views.monthly" + "core.ui.calendar.views.monthly", }, } end @@ -35,7 +35,7 @@ module.private = { print("Error: view not set or not available") end, - extract_ui_info = function (buffer, window) + extract_ui_info = function(buffer, window) local width = vim.api.nvim_win_get_width(window) local height = vim.api.nvim_win_get_height(window) @@ -52,7 +52,7 @@ module.private = { } end, - open_window = function (options) + open_window = function(options) local buffer, window = module.required["core.ui"].create_split( "calendar", {}, @@ -60,7 +60,7 @@ module.private = { ) return buffer, window - end + end, } module.public = { @@ -73,12 +73,12 @@ module.public = { end, create_calendar = function(buffer, window, options) - local callback_and_close = function (result) + local callback_and_close = function(result) if options.callback ~= nil then options.callback(result) end - module.required['core.ui'].delete_window(buffer) + module.required["core.ui"].delete_window(buffer) end local mode = module.private.get_mode(options.mode, callback_and_close) diff --git a/lua/neorg/modules/core/ui/calendar/views/monthly.lua b/lua/neorg/modules/core/ui/calendar/views/monthly.lua index 1e563780f..1c210e131 100644 --- a/lua/neorg/modules/core/ui/calendar/views/monthly.lua +++ b/lua/neorg/modules/core/ui/calendar/views/monthly.lua @@ -1,14 +1,14 @@ -local module = neorg.modules.create('core.ui.calendar.views.monthly') +local module = neorg.modules.create("core.ui.calendar.views.monthly") local function reformat_time(date) return os.date("*t", os.time(date)) end -module.setup = function () +module.setup = function() return { requires = { - 'core.ui.calendar' - } + "core.ui.calendar", + }, } end @@ -168,13 +168,25 @@ module.private = { weekdays_string_length = weekdays_string_length + (i ~= 7 and 4 or 2) end + -- This serves as the index of this week banner extmark inside the extmark table local absolute_offset = offset + (offset < 0 and (-offset * 100) or 0) + local extmark_position = 0 + + -- Calculate offset position only for the previous and following months + if offset ~= 0 then + extmark_position = (weekdays_string_length * math.abs(offset)) + (distance * math.abs(offset)) + end + + -- For previous months, revert the offset + if offset < 0 then + extmark_position = -extmark_position + end + local weekday_banner_id = module.private.set_decorational_extmark( ui_info, 6, - (weekdays_string_length * offset) - + (offset < 0 and -distance or (offset > 0 and distance or 0)) * math.abs(offset), + extmark_position, weekdays_string_length, weekdays, "center", @@ -295,7 +307,7 @@ module.private = { module.private.render_month_banner(ui_info, positive_target_date, weekday_banner) module.private.render_month(ui_info, positive_target_date, weekday_banner) - weekday_banner = module.private.render_weekday_banner(ui_info, i * -1) + weekday_banner = module.private.render_weekday_banner(ui_info, i * -1, options.distance) local negative_target_date = reformat_time({ year = date.year, @@ -511,7 +523,7 @@ module.public = { view_name = "monthly", - setup = function (ui_info, mode, options) + setup = function(ui_info, mode, options) options.distance = options.distance or 4 module.private.current_mode = mode @@ -574,12 +586,11 @@ module.public = { end end, { buffer = ui_info.buffer }) end - - end + end, } -module.load = function () - module.required['core.ui.calendar'].add_view(module.public.view_name, module.public) +module.load = function() + module.required["core.ui.calendar"].add_view(module.public.view_name, module.public) end return module diff --git a/lua/neorg/modules/core/ui/module.lua b/lua/neorg/modules/core/ui/module.lua index 5a3028338..11cfd40a4 100644 --- a/lua/neorg/modules/core/ui/module.lua +++ b/lua/neorg/modules/core/ui/module.lua @@ -22,8 +22,8 @@ module.setup = function() "text_popup", }, requires = { - "core.ui.calendar" - } + "core.ui.calendar", + }, } end