@@ -5,6 +5,7 @@ local config = require('orgmode.config')
55local namespace = vim .api .nvim_create_namespace (' org_calendar' )
66local colors = require (' orgmode.colors' )
77local Range = require (' orgmode.files.elements.range' )
8+ local Input = require (' orgmode.ui.input' )
89
910--- @alias OrgCalendarOnRenderDayOpts { line : number , from : number , to : number , buf : number , namespace : number }
1011--- @alias OrgCalendarOnRenderDay fun ( day : OrgDate , opts : OrgCalendarOnRenderDayOpts )
@@ -71,6 +72,7 @@ function Calendar:open()
7172 title_pos = ' center' ,
7273 }
7374 end
75+ self .prev_win = vim .api .nvim_get_current_win ()
7476
7577 self .buf = vim .api .nvim_create_buf (false , true )
7678 vim .api .nvim_buf_set_name (self .buf , ' orgcalendar' )
@@ -592,6 +594,7 @@ function Calendar:select()
592594
593595 vim .cmd ([[ echon]] )
594596 vim .api .nvim_win_close (0 , true )
597+ vim .api .nvim_set_current_win (self .prev_win )
595598 return cb (selected_date )
596599end
597600
@@ -600,6 +603,7 @@ function Calendar:dispose()
600603 self .buf = nil
601604 if self .callback then
602605 self .callback (nil )
606+ vim .api .nvim_set_current_win (self .prev_win )
603607 self .callback = nil
604608 end
605609end
@@ -609,15 +613,16 @@ function Calendar:clear_date()
609613 self .callback = nil
610614 vim .cmd ([[ echon]] )
611615 vim .api .nvim_win_close (0 , true )
616+ vim .api .nvim_set_current_win (self .prev_win )
612617 cb (nil , true )
613618end
614619
615620function Calendar :read_date ()
616621 self :_ensure_day ()
617622 local current_date = self :get_selected_date () or Date .today ()
618- vim . ui . input ({ prompt = ' Enter date: ' , default = current_date :to_string () }, function (result )
623+ Input . open ( ' Enter date: ' , current_date :to_string ()): next ( function (result )
619624 if result then
620- local date = Date . from_string (result )
625+ local date = current_date : set_from_string (result )
621626 if not date then
622627 date = current_date :adjust (result )
623628 end
0 commit comments