@@ -545,22 +545,26 @@ function Headline:get_append_line()
545
545
end
546
546
local plan = self :node ():parent ():field (' plan' )[1 ]
547
547
if plan then
548
- local row = plan :end_ ()
549
- return row
548
+ local _ , _ , has_plan_dates = self :get_plan_dates ()
549
+ if has_plan_dates then
550
+ local row = plan :end_ ()
551
+ return row
552
+ end
550
553
end
551
554
local row = self :node ():end_ ()
552
555
return row
553
556
end
554
557
555
558
memoize (' get_plan_dates' )
556
- --- @return OrgTable<OrgPlanDateTypes , OrgDate[]>,OrgTable<OrgPlanDateTypes , TSNode>
559
+ --- @return OrgTable<OrgPlanDateTypes , OrgDate[]>,OrgTable<OrgPlanDateTypes , TSNode> , boolean
557
560
function Headline :get_plan_dates ()
558
561
local plan = self :node ():parent ():field (' plan' )[1 ]
559
562
local dates = {}
560
563
local dates_nodes = {}
564
+ local has_plan_dates = false
561
565
562
566
if not plan then
563
- return dates , dates_nodes
567
+ return dates , dates_nodes , has_plan_dates
564
568
end
565
569
566
570
local valid_plan_types = { ' SCHEDULED' , ' DEADLINE' , ' CLOSED' , ' NONE' }
@@ -571,14 +575,17 @@ function Headline:get_plan_dates()
571
575
local timestamp = node :field (' timestamp' )[1 ]
572
576
573
577
if vim .tbl_contains (valid_plan_types , name :upper ()) then
578
+ if name_node then
579
+ has_plan_dates = true
580
+ end
574
581
dates [name :upper ()] = Date .from_org_date (self .file :get_node_text (timestamp ), {
575
582
range = Range .from_node (timestamp ),
576
583
type = name :upper (),
577
584
})
578
585
dates_nodes [name :upper ()] = node
579
586
end
580
587
end
581
- return dates , dates_nodes
588
+ return dates , dates_nodes , has_plan_dates
582
589
end
583
590
584
591
memoize (' get_all_dates' )
809
816
--- @param active ? boolean
810
817
--- @private
811
818
function Headline :_add_date (type , date , active )
812
- local _ , date_nodes = self :get_plan_dates ()
819
+ local _ , date_nodes , has_plan_dates = self :get_plan_dates ()
813
820
local text = type .. ' : ' .. date :to_wrapped_string (active )
814
- if vim . tbl_isempty ( date_nodes ) then
821
+ if not has_plan_dates then
815
822
local indentation = config :get_indent (self :get_level () + 1 )
816
823
local start_line = self :node ():start ()
817
824
vim .fn .append (start_line + 1 , (' %s%s' ):format (indentation , text ))
0 commit comments