diff --git a/lua/navigator/render.lua b/lua/navigator/render.lua index 95fc086..36f799a 100644 --- a/lua/navigator/render.lua +++ b/lua/navigator/render.lua @@ -1,7 +1,9 @@ -local log = require('guihua.log').info -local trace = require('guihua.log').trace -local M = {} +local util = require('navigator.util') +local log = util.log +local trace = util.trace local clone = require('guihua.util').clone + +local M = {} local function filename(url) if url == nil then return '' @@ -162,15 +164,7 @@ function M.prepare_for_render(items, opts) end if trim then item.text = string.sub(item.text, 1, l) - local _, j = string.gsub(item.text, [["]], '') - if j % 2 == 1 then - item.text = item.text .. '"' - end - _, j = string.gsub(item.text, [[']], '') - if j % 2 == 1 then - item.text = item.text .. [[']] - end - item.text = item.text .. '' + item.text = util.sub_match(item.text) -- let check if there are unmatched "/' end if #space + #item.text + #ts_report >= win_width then diff --git a/lua/navigator/treesitter.lua b/lua/navigator/treesitter.lua index 06395de..599fcfb 100644 --- a/lua/navigator/treesitter.lua +++ b/lua/navigator/treesitter.lua @@ -193,7 +193,8 @@ 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) + local str = text:sub(1, text_len) + return util.sub_match(str) end return text diff --git a/lua/navigator/util.lua b/lua/navigator/util.lua index bb79d5d..9aac780 100644 --- a/lua/navigator/util.lua +++ b/lua/navigator/util.lua @@ -556,4 +556,17 @@ function M.dirname(pathname) return result end +function M.sub_match(str) + local _, j = string.gsub(str, [["]], '') + if j % 2 == 1 then + str = str .. '"' + end + _, j = string.gsub(str, [[']], '') + if j % 2 == 1 then + str = str .. [[']] + end + str = str .. '' + return str +end + return M