Skip to content

Commit 8008c58

Browse files
fix: Consider date a plan date only if it has a name
1 parent 955acfc commit 8008c58

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lua/orgmode/files/headline.lua

+14-7
Original file line numberDiff line numberDiff line change
@@ -545,22 +545,26 @@ function Headline:get_append_line()
545545
end
546546
local plan = self:node():parent():field('plan')[1]
547547
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
550553
end
551554
local row = self:node():end_()
552555
return row
553556
end
554557

555558
memoize('get_plan_dates')
556-
---@return OrgTable<OrgPlanDateTypes, OrgDate[]>,OrgTable<OrgPlanDateTypes, TSNode>
559+
---@return OrgTable<OrgPlanDateTypes, OrgDate[]>,OrgTable<OrgPlanDateTypes, TSNode>, boolean
557560
function Headline:get_plan_dates()
558561
local plan = self:node():parent():field('plan')[1]
559562
local dates = {}
560563
local dates_nodes = {}
564+
local has_plan_dates = false
561565

562566
if not plan then
563-
return dates, dates_nodes
567+
return dates, dates_nodes, has_plan_dates
564568
end
565569

566570
local valid_plan_types = { 'SCHEDULED', 'DEADLINE', 'CLOSED', 'NONE' }
@@ -571,14 +575,17 @@ function Headline:get_plan_dates()
571575
local timestamp = node:field('timestamp')[1]
572576

573577
if vim.tbl_contains(valid_plan_types, name:upper()) then
578+
if name_node then
579+
has_plan_dates = true
580+
end
574581
dates[name:upper()] = Date.from_org_date(self.file:get_node_text(timestamp), {
575582
range = Range.from_node(timestamp),
576583
type = name:upper(),
577584
})
578585
dates_nodes[name:upper()] = node
579586
end
580587
end
581-
return dates, dates_nodes
588+
return dates, dates_nodes, has_plan_dates
582589
end
583590

584591
memoize('get_all_dates')
@@ -809,9 +816,9 @@ end
809816
---@param active? boolean
810817
---@private
811818
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()
813820
local text = type .. ': ' .. date:to_wrapped_string(active)
814-
if vim.tbl_isempty(date_nodes) then
821+
if not has_plan_dates then
815822
local indentation = config:get_indent(self:get_level() + 1)
816823
local start_line = self:node():start()
817824
vim.fn.append(start_line + 1, ('%s%s'):format(indentation, text))

0 commit comments

Comments
 (0)