diff --git a/lua/orgmode/agenda/init.lua b/lua/orgmode/agenda/init.lua index 1b2b3f973..7e6d79fa3 100644 --- a/lua/orgmode/agenda/init.lua +++ b/lua/orgmode/agenda/init.lua @@ -17,7 +17,9 @@ local Promise = require('orgmode.utils.promise') ---@field views table[] ---@field filters OrgAgendaFilter ---@field files OrgFiles -local Agenda = {} +local Agenda = { + _ns_id = vim.api.nvim_create_namespace('orgmode.ui.agenda'), +} ---@param opts? table function Agenda:new(opts) @@ -161,11 +163,24 @@ function Agenda:_render(skip_rebuild) vim.w.org_window_pos = nil end end - local lines = vim.tbl_map(function(item) - return item.line_content - end, self.content) vim.bo.modifiable = true - vim.api.nvim_buf_set_lines(0, 0, -1, true, lines) + for index, item in ipairs(self.content) do + vim.api.nvim_buf_set_lines(0, index - 1, -1, true, { item.line_content }) + if item.headline and #item.headline:get_tags() > 0 then + -- Get the first highlight group from the given item and apply it to the tag if available. If + -- not use the generic `Normal` hl group + local extmark_hls = { + (item.highlights and item.highlights[1] and item.highlights[1].hlgroup) and item.highlights[1].hlgroup + or 'Normal', + '@org.agenda.tag', + } + vim.api.nvim_buf_set_extmark(0, self._ns_id, index - 1, 0, { + virt_text = { { item.headline:tags_to_string(), extmark_hls } }, + virt_text_pos = 'right_align', + hl_mode = 'combine', + }) + end + end vim.bo.modifiable = false vim.bo.modified = false colors.highlight(self.highlights, true) diff --git a/lua/orgmode/agenda/views/agenda.lua b/lua/orgmode/agenda/views/agenda.lua index afd649957..1e3ca5978 100644 --- a/lua/orgmode/agenda/views/agenda.lua +++ b/lua/orgmode/agenda/views/agenda.lua @@ -293,12 +293,6 @@ function AgendaView.build_agenda_item_content(agenda_item, longest_category, lon todo_keyword = todo_padding .. todo_keyword local line = string.format('%s%s%s %s', category, date, todo_keyword, headline:get_title_with_priority()) local todo_keyword_pos = string.format('%s%s%s', category, date, todo_padding):len() - if #headline:get_tags() > 0 then - local tags_string = headline:tags_to_string() - local padding_length = math.max(1, win_width - vim.api.nvim_strwidth(line) - vim.api.nvim_strwidth(tags_string)) - local indent = string.rep(' ', padding_length) - line = string.format('%s%s%s', line, indent, tags_string) - end local item_highlights = {} if #agenda_item.highlights then diff --git a/lua/orgmode/org/mappings.lua b/lua/orgmode/org/mappings.lua index 9c3256404..28d71bb62 100644 --- a/lua/orgmode/org/mappings.lua +++ b/lua/orgmode/org/mappings.lua @@ -645,7 +645,7 @@ function OrgMappings:meta_return(suffix) end if #text_edits > 0 then - vim.lsp.util.apply_text_edits(text_edits, 0, constants.default_offset_encoding) + vim.lsp.util.apply_text_edits(text_edits, vim.api.nvim_get_current_buf(), constants.default_offset_encoding) vim.fn.cursor(end_row + 1 + (add_empty_line and 1 or 0), 1) -- +1 for next line