diff --git a/lua/orgmode/api/headline.lua b/lua/orgmode/api/headline.lua index 5e1d44dfe..88d7c6a3e 100644 --- a/lua/orgmode/api/headline.lua +++ b/lua/orgmode/api/headline.lua @@ -63,7 +63,7 @@ end ---@private function OrgHeadline._build_from_internal_headline(section, index) local todo, _, type = section:get_todo() - local _, properties = section:get_properties() + local properties = section:get_properties() return OrgHeadline:_new({ title = section:get_title(), line = section:get_headline_line_content(), diff --git a/lua/orgmode/files/file.lua b/lua/orgmode/files/file.lua index e5d20b367..1e19fb5d4 100644 --- a/lua/orgmode/files/file.lua +++ b/lua/orgmode/files/file.lua @@ -241,7 +241,7 @@ function OrgFile:apply_search(search, todo_only) local deadline = item:get_deadline_date() local scheduled = item:get_scheduled_date() local closed = item:get_closed_date() - local _, properties = item:get_properties() + local properties = item:get_properties() return search:check({ props = vim.tbl_extend('keep', {}, properties, { diff --git a/lua/orgmode/files/headline.lua b/lua/orgmode/files/headline.lua index 6b37f4093..ff1829470 100644 --- a/lua/orgmode/files/headline.lua +++ b/lua/orgmode/files/headline.lua @@ -186,9 +186,8 @@ end ---@return OrgDate | nil function Headline:get_closed_date() - return utils.find(self:get_all_dates(), function(date) - return date:is_closed() - end) + local dates = self:get_plan_dates() + return vim.tbl_get(dates, 'CLOSED', 1) end function Headline:get_priority_sort_value() @@ -361,13 +360,14 @@ function Headline:get_title_with_priority() return title end ----@return TSNode | nil, table +memoize('get_properties') +---@return table, TSNode | nil function Headline:get_properties() local section = self:node():parent() local properties_node = section and section:field('property_drawer')[1] if not properties_node then - return nil, {} + return {}, nil end local properties = {} @@ -383,7 +383,7 @@ function Headline:get_properties() end end - return properties_node, properties + return properties, properties_node end ---@param name string @@ -397,19 +397,19 @@ function Headline:set_property(name, value) vim.fn.deletebufline(bufnr, property_node:start() + 1) end self:refresh() - local properties_node, properties = self:get_properties() + local properties, properties_node = self:get_properties() if vim.tbl_isempty(properties) then self:_set_node_lines(properties_node, {}) end return self:refresh() end - local properties = self:get_properties() + local _, properties = self:get_properties() if not properties then local append_line = self:get_append_line() local property_drawer = self:_apply_indent({ ':PROPERTIES:', ':END:' }) --[[ @as string[] ]] vim.api.nvim_buf_set_lines(bufnr, append_line, append_line, false, property_drawer) - properties = self:refresh():get_properties() + _, properties = self:refresh():get_properties() end local property = (':%s: %s'):format(name, value) @@ -445,7 +445,7 @@ end ---@param search_parents? boolean ---@return string | nil, TSNode | nil function Headline:get_property(property_name, search_parents) - local properties = self:get_properties() + local _, properties = self:get_properties() if properties then for _, node in ipairs(ts_utils.get_named_children(properties)) do local name = node:field('name')[1] @@ -598,7 +598,7 @@ end ---@return number function Headline:get_append_line() - local properties = self:get_properties() + local _, properties = self:get_properties() if properties then local row = properties:end_() return row @@ -853,6 +853,7 @@ function Headline:get_drawer_append_line(name) return name_row + 1 end +memoize('get_range') ---@return OrgRange function Headline:get_range() return Range.from_node(self:node():parent()) @@ -863,6 +864,7 @@ function Headline:get_lines() return self.file:get_node_text_list(self:node():parent()) end +memoize('get_headline_line_content') ---@return string function Headline:get_headline_line_content() local line = self.file:get_node_text(self:node()):gsub('\n', '') diff --git a/lua/orgmode/org/mappings.lua b/lua/orgmode/org/mappings.lua index bcd21642f..a12dc20a3 100644 --- a/lua/orgmode/org/mappings.lua +++ b/lua/orgmode/org/mappings.lua @@ -457,7 +457,7 @@ function OrgMappings:_todo_change_state(direction) ) if log_repeat_enabled then - headline:set_property('LAST_REPEAT', Date.now():to_wrapped_string(false)) + item:set_property('LAST_REPEAT', Date.now():to_wrapped_string(false)) end if not prompt_repeat_note and not prompt_done_note then