Skip to content

Commit a47492f

Browse files
Fix padding headline tags when headline contains non-standard width chars
1 parent 1a52ca2 commit a47492f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lua/orgmode/agenda/views/agenda.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ function AgendaView:build()
190190

191191
local longest_items = utils.reduce(agenda_items, function(acc, agenda_item)
192192
acc.category = math.max(acc.category, agenda_item.headline:get_category():len())
193-
acc.label = math.max(acc.label, agenda_item.label:len())
193+
acc.label = math.max(acc.label, vim.api.nvim_strwidth(agenda_item.label))
194194
return acc
195195
end, {
196196
category = 0,
@@ -281,7 +281,9 @@ function AgendaView.build_agenda_item_content(agenda_item, longest_category, lon
281281
local line = string.format('%s%s%s %s', category, date, todo_keyword, headline.title)
282282
local todo_keyword_pos = string.format('%s%s%s', category, date, todo_padding):len()
283283
if #headline.tags > 0 then
284-
line = string.format('%-99s %s', line, headline:tags_to_string())
284+
local padding_length = math.max(0, 99 - vim.api.nvim_strwidth(line))
285+
local indent = string.rep(' ', padding_length)
286+
line = string.format('%s%s %s', line, indent, headline:tags_to_string())
285287
end
286288

287289
local item_highlights = {}

lua/orgmode/org/mappings.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ function OrgMappings:_set_headline_tags(headline, tags_string)
868868
local line_without_tags = headline.line
869869
:gsub(vim.pesc(utils.tags_to_string(headline:get_own_tags())) .. '%s*$', '')
870870
:gsub('%s*$', '')
871-
local spaces = 80 - math.min(line_without_tags:len(), 79)
871+
local spaces = 80 - math.min(vim.api.nvim_strwidth(line_without_tags), 79)
872872
local new_line = string.format('%s%s%s', line_without_tags, string.rep(' ', spaces), tags):gsub('%s*$', '')
873873
return vim.fn.setline(headline.range.start_line, new_line)
874874
end

0 commit comments

Comments
 (0)