Skip to content

Commit

Permalink
feat(calendar-ui): new mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
benlubas authored and vhyrro committed Jun 27, 2024
1 parent 6b4751c commit 2a4081f
Showing 1 changed file with 118 additions and 0 deletions.
118 changes: 118 additions & 0 deletions lua/neorg/modules/core/ui/calendar/views/monthly.lua
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,124 @@ module.public = {
date = new_date
end, { buffer = ui_info.buffer })

vim.keymap.set("n", "c", function()
local new_date = reformat_time({
year = date.year + 100 * count(),
month = date.month,
day = date.day,
})
view:render_view(ui_info, new_date, date, options)
date = new_date
end, { buffer = ui_info.buffer })

vim.keymap.set("n", "C", function()
local new_date = reformat_time({
year = date.year - 100 * count(),
month = date.month,
day = date.day,
})
view:render_view(ui_info, new_date, date, options)
date = new_date
end, { buffer = ui_info.buffer })

vim.keymap.set("n", "d", function()
local new_date = reformat_time({
year = date.year + 10 * count(),
month = date.month,
day = date.day,
})
view:render_view(ui_info, new_date, date, options)
date = new_date
end, { buffer = ui_info.buffer })

vim.keymap.set("n", "D", function()
local new_date = reformat_time({
year = date.year - 10 * count(),
month = date.month,
day = date.day,
})
view:render_view(ui_info, new_date, date, options)
date = new_date
end, { buffer = ui_info.buffer })

vim.keymap.set("n", "e", function()
local new_date = reformat_time({
year = date.year,
month = date.month + count(),
day = module.private.get_month_length(date.month + count(), date.year)
})
view:render_view(ui_info, new_date, date, options)
date = new_date
end, { buffer = ui_info.buffer })

vim.keymap.set("n", "E", function()
local new_date = reformat_time({
year = date.year,
month = date.month - count(),
day = module.private.get_month_length(date.month - count(), date.year)
})
view:render_view(ui_info, new_date, date, options)
date = new_date
end, { buffer = ui_info.buffer })

vim.keymap.set("n", "w", function()
local new_date = reformat_time({
year = date.year,
month = date.month,
day = date.day + 7 * count()
})
view:render_view(ui_info, new_date, date, options)
date = new_date
end, { buffer = ui_info.buffer })

vim.keymap.set("n", "W", function()
local new_date = reformat_time({
year = date.year,
month = date.month,
day = date.day - 7 * count()
})
view:render_view(ui_info, new_date, date, options)
date = new_date
end, { buffer = ui_info.buffer })

-- TODO: I'm not sure how to do f mappings the native way. It's not operator pending
-- mode, and I can't find anything in the help docs. Using on_key like this doesn't work
-- either.
-- vim.keymap.set("n", "f", function()
-- local ns = vim.api.nvim_create_namespace("neorg_cal_f")
-- print("waiting...")
-- vim.on_key(function(key, typed)
-- -- typed is the char we're dealing with
-- print("key:", key)
-- print("typed:", typed)
-- local months = {}
-- for i = 1, 12 do
-- table.insert(
-- months,
-- (os.date("%B", os.time({ year = 2000, month = i, day = 1 })) --[[@as string]]):lower()
-- )
-- end
-- print("months:")
-- P(months)
-- for i = date.month, date.month + 12 do
-- local m = ((i - 1) % 12) + 1
-- if months[m]:match("^" .. typed) then
-- print("match", months[m])
-- date.month = m
-- break
-- end
-- end
-- vim.on_key(nil, ns)
-- local new_date = reformat_time({
-- year = date.year,
-- month = date.month,
-- day = date.day,
-- })
-- view:render_view(ui_info, new_date, date, options)
-- date = new_date
-- end, ns)
-- end)

vim.keymap.set(
"n",
"?",
Expand Down

0 comments on commit 2a4081f

Please sign in to comment.