From fb87a0b1b7a0c75f8f96e5e61989a43d4dc8dec6 Mon Sep 17 00:00:00 2001 From: ray-x Date: Thu, 1 Sep 2022 04:32:14 +1000 Subject: [PATCH] long line improvement --- lua/navigator/render.lua | 10 +++++++--- lua/navigator/treesitter.lua | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lua/navigator/render.lua b/lua/navigator/render.lua index 37f810d..95fc086 100644 --- a/lua/navigator/render.lua +++ b/lua/navigator/render.lua @@ -69,7 +69,7 @@ function M.prepare_for_render(items, opts) icon = devicons.get_icon(fn, ext) or icon end -- local call_by_presented = false - opts.width = opts.width or math.floor( vim.api.nvim_get_option('columns') * 0.8) + opts.width = opts.width or math.floor(vim.api.nvim_get_option('columns') * 0.8) local win_width = opts.width -- buf for i = 1, #items do @@ -155,9 +155,13 @@ function M.prepare_for_render(items, opts) end if #ts_report > 1 then space, trim = get_pads(win_width, item.text, ts_report) + + local l = math.max(20, opts.width - math.min(20, #ts_report)) + if trim and #item.text < l then + trim = false + end if trim then - local ts_r = ts_report or '' - item.text = string.sub(item.text, 1, math.max(1, opts.width - math.max(20, #ts_r))) + item.text = string.sub(item.text, 1, l) local _, j = string.gsub(item.text, [["]], '') if j % 2 == 1 then item.text = item.text .. '"' diff --git a/lua/navigator/treesitter.lua b/lua/navigator/treesitter.lua index 3de1c86..06395de 100644 --- a/lua/navigator/treesitter.lua +++ b/lua/navigator/treesitter.lua @@ -193,7 +193,7 @@ function M.ref_context(opts) local text = table.concat(lines, separator) local text_len = #text if text_len > indicator_size then - return "..." .. text:sub(text_len - indicator_size, text_len) + return '' .. text:sub(text_len - indicator_size, text_len) end return text