nvim: fold 套用flarocca的範例
This commit is contained in:
parent
3eee006f55
commit
58cc147801
@ -48,7 +48,9 @@ return {
|
|||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
local handler = function(virtText, lnum, endLnum, width, truncate)
|
local handler = function(virtText, lnum, endLnum, width, truncate)
|
||||||
local newVirtText = {}
|
local newVirtText = {}
|
||||||
local suffix = (' %d '):format(endLnum - lnum)
|
local totalLines = vim.api.nvim_buf_line_count(0)
|
||||||
|
local foldedLines = endLnum - lnum
|
||||||
|
local suffix = (" %d %d%%"):format(foldedLines, foldedLines / totalLines * 100)
|
||||||
local sufWidth = vim.fn.strdisplaywidth(suffix)
|
local sufWidth = vim.fn.strdisplaywidth(suffix)
|
||||||
local targetWidth = width - sufWidth
|
local targetWidth = width - sufWidth
|
||||||
local curWidth = 0
|
local curWidth = 0
|
||||||
@ -62,15 +64,16 @@ return {
|
|||||||
local hlGroup = chunk[2]
|
local hlGroup = chunk[2]
|
||||||
table.insert(newVirtText, { chunkText, hlGroup })
|
table.insert(newVirtText, { chunkText, hlGroup })
|
||||||
chunkWidth = vim.fn.strdisplaywidth(chunkText)
|
chunkWidth = vim.fn.strdisplaywidth(chunkText)
|
||||||
-- str width returned from truncate() may less than 2nd argument, need padding
|
|
||||||
if curWidth + chunkWidth < targetWidth then
|
if curWidth + chunkWidth < targetWidth then
|
||||||
suffix = suffix .. (' '):rep(targetWidth - curWidth - chunkWidth)
|
suffix = suffix .. (" "):rep(targetWidth - curWidth - chunkWidth)
|
||||||
end
|
end
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
curWidth = curWidth + chunkWidth
|
curWidth = curWidth + chunkWidth
|
||||||
end
|
end
|
||||||
table.insert(newVirtText, {suffix, 'MoreMsg'})
|
local rAlignAppndx = math.max(math.min(vim.opt.textwidth["_value"], width - 1) - curWidth - sufWidth, 0)
|
||||||
|
suffix = (" "):rep(rAlignAppndx) .. suffix
|
||||||
|
table.insert(newVirtText, { suffix, "MoreMsg" })
|
||||||
return newVirtText
|
return newVirtText
|
||||||
end
|
end
|
||||||
opts["fold_virt_text_handler"] = handler
|
opts["fold_virt_text_handler"] = handler
|
||||||
|
Loading…
x
Reference in New Issue
Block a user