@@ -135,7 +135,6 @@ function Calendar:open()
135
135
self :set_time ()
136
136
end , map_opts )
137
137
if self :has_time () then
138
- print (' apply clear_time' )
139
138
vim .keymap .set (' n' , ' T' , function ()
140
139
self :clear_time ()
141
140
end , map_opts )
@@ -206,7 +205,7 @@ function Calendar:render()
206
205
if self .select_state == SelState .DAY then
207
206
table.insert (content , ' [t] - enter time [T] - clear time' )
208
207
else
209
- table.insert (content , ' [d] - enter time [T] - clear time' )
208
+ table.insert (content , ' [d] - select day [T] - clear time' )
210
209
end
211
210
else
212
211
table.insert (content , ' [t] - enter time' )
@@ -314,7 +313,15 @@ function Calendar:has_time()
314
313
return not self .date .date_only
315
314
end
316
315
316
+ --- @private
317
+ function Calendar :_ensure_day ()
318
+ if self .select_state ~= SelState .DAY then
319
+ self :set_day ()
320
+ end
321
+ end
322
+
317
323
function Calendar :forward ()
324
+ self :_ensure_day ()
318
325
self .month = self .month :add ({ month = vim .v .count1 })
319
326
self :render ()
320
327
vim .fn .cursor (2 , 1 )
@@ -323,6 +330,7 @@ function Calendar:forward()
323
330
end
324
331
325
332
function Calendar :backward ()
333
+ self :_ensure_day ()
326
334
self .month = self .month :subtract ({ month = vim .v .count1 })
327
335
self :render ()
328
336
vim .fn .cursor (vim .fn .line (' $' ), 0 )
@@ -490,6 +498,7 @@ function Calendar:cursor_down()
490
498
end
491
499
492
500
function Calendar :reset ()
501
+ self :_ensure_day ()
493
502
local today = self .month :set_todays_date ()
494
503
self .month = today :set ({ day = 1 })
495
504
self :render ()
@@ -556,12 +565,13 @@ function Calendar:clear_date()
556
565
end
557
566
558
567
function Calendar :read_date ()
559
- local default = self :get_selected_date ():to_string ()
560
- vim .ui .input ({ prompt = ' Enter date: ' , default = default }, function (result )
568
+ self :_ensure_day ()
569
+ local current_date = self :get_selected_date ()
570
+ vim .ui .input ({ prompt = ' Enter date: ' , default = current_date :to_string () }, function (result )
561
571
if result then
562
572
local date = Date .from_string (result )
563
573
if not date then
564
- date = self : get_selected_date () :adjust (result )
574
+ date = current_date :adjust (result )
565
575
end
566
576
567
577
self .date = date
0 commit comments