Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.0 KiB

  1. local handler = function(virtText, lnum, endLnum, width, truncate)
  2. local newVirtText = {}
  3. local suffix = (" 󰁂 %d "):format(endLnum - lnum)
  4. local sufWidth = vim.fn.strdisplaywidth(suffix)
  5. local targetWidth = width - sufWidth
  6. local curWidth = 0
  7. for _, chunk in ipairs(virtText) do
  8. local chunkText = chunk[1]
  9. local chunkWidth = vim.fn.strdisplaywidth(chunkText)
  10. if targetWidth > curWidth + chunkWidth then
  11. table.insert(newVirtText, chunk)
  12. else
  13. chunkText = truncate(chunkText, targetWidth - curWidth)
  14. local hlGroup = chunk[2]
  15. table.insert(newVirtText, { chunkText, hlGroup })
  16. chunkWidth = vim.fn.strdisplaywidth(chunkText)
  17. -- str width returned from truncate() may less than 2nd argument, need padding
  18. if curWidth + chunkWidth < targetWidth then
  19. suffix = suffix .. (" "):rep(targetWidth - curWidth - chunkWidth)
  20. end
  21. break
  22. end
  23. curWidth = curWidth + chunkWidth
  24. end
  25. table.insert(newVirtText, { suffix, "MoreMsg" })
  26. return newVirtText
  27. end
  28. return {
  29. fold_virt_text_handler = handler,
  30. }