1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 11:30:06 +08:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Eric Wong
113110b163 perf(zettelkasten): check title width 2024-12-22 23:43:24 +08:00
Eric Wong
afe49af8a3 fix(zettelkasten): use string.sub for long title 2024-12-22 23:05:15 +08:00

View File

@ -7,6 +7,15 @@
--============================================================================= --=============================================================================
local M = {} local M = {}
local function str2chars(str)
local t = {}
for _, k in ipairs(vim.fn.split(str, '\\zs')) do
table.insert(t, k)
end
return t
end
local s_formatters = { local s_formatters = {
['%r'] = function(line) ['%r'] = function(line)
return #line.references return #line.references
@ -18,10 +27,20 @@ local s_formatters = {
return vim.fn.fnamemodify(line.file_name, ':t') return vim.fn.fnamemodify(line.file_name, ':t')
end, end,
['%h'] = function(line) ['%h'] = function(line)
if vim.fn.strdisplaywidth(line.title) <= 30 then if vim.fn.strdisplaywidth(line.title) < 30 then
return line.title .. string.rep(' ', 30 - vim.fn.strdisplaywidth(line.title)) return line.title .. string.rep(' ', 30 - vim.fn.strdisplaywidth(line.title))
else
local t = ''
for _, char in ipairs(str2chars(line.title)) do
if vim.fn.strdisplaywidth(t) + vim.fn.strdisplaywidth(char) <= 27 then
t = t .. char
else
break
end
end
t = t .. '...'
return t .. string.rep(' ', 30 - vim.fn.strdisplaywidth(t))
end end
return line.title
end, end,
['%d'] = function(line) ['%d'] = function(line)
return line.id return line.id