1- local fn = vim .fn
21local cFunc = require (" hlchunk.utils.cFunc" )
32
43-- get the virtual indent of the given line
@@ -24,6 +23,7 @@ local indentHelper = {}
2423--- @return number render_num , number offset , number shadowed_num return the render char number and the start index of the
2524-- first render char, the last is shadowed char number
2625function indentHelper .calc (blank , leftcol , sw )
26+ blank = blank or " "
2727 local blankLen = type (blank ) == " string" and # blank or blank --[[ @as number]]
2828 if blankLen - leftcol <= 0 or sw <= 0 then
2929 return 0 , 0 , 0
@@ -68,18 +68,17 @@ local function get_rows_indent_by_treesitter(range)
6868 end
6969
7070 local bufnr = range .bufnr
71- for i = range .start , range .finish , - 1 do
72- rows_indent [i ] = vim .api .nvim_buf_call (bufnr , function ()
73- local indent = ts_indent .get_indent (i + 1 )
74- if indent == - 1 then
75- indent = fn .indent (i + 1 )
76- if indent == 0 and cFunc .get_line_len (bufnr , i ) == 0 then
77- indent = get_virt_indent (bufnr , i )
78- end
79- end
80- --- @diagnostic disable-next-line : redundant-return-value
81- return indent
71+ for i = range .start , range .finish , 1 do
72+ local t1 = vim .api .nvim_buf_call (bufnr , function ()
73+ return ts_indent .get_indent (i + 1 )
8274 end )
75+ local t2 = cFunc .get_indent (bufnr , i )
76+ local line_len = cFunc .get_line_len (bufnr , i )
77+ local indent = math.min (t1 , t2 )
78+ if indent == 0 and line_len == 0 then
79+ indent = get_virt_indent (bufnr , i )
80+ end
81+ rows_indent [i ] = indent
8382 end
8483
8584 return indentHelper .ROWS_INDENT_RETCODE .OK , rows_indent
0 commit comments