Skip to content

Commit

Permalink
fix: remove is_tab in snapshot store in context
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed Aug 28, 2024
1 parent 15ba2c3 commit 8cbb1b6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lua/indentmini/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ end
--- @return integer the shiftwidth value of bufnr
local function get_shiftw_value(bufnr)
local handle = find_buffer_by_handle(bufnr, ffi.new('Error'))
return get_sw_value(handle)
return handle and get_sw_value(handle) or 0
end

--- store the line data in snapshot and update the blank line indent
Expand Down Expand Up @@ -97,10 +97,12 @@ local function make_snapshot(lnum)
if is_empty then
indent_cols = indent
end
if not context.is_tab and line_text:find('^\t') then
context.is_tab = true
end
local snapshot = {
indent = indent,
is_empty = is_empty,
is_tab = line_text:find('^\t') and true or false,
indent_cols = indent_cols,
}

Expand Down Expand Up @@ -164,7 +166,7 @@ local function on_line(_, _, bufnr, row)
for i = 1, sp.indent - 1, context.step do
local col = i - 1
local level = math.floor(col / context.step) + 1
if not vim.o.expandtab or sp.is_tab then
if not vim.bo[bufnr].expandtab or context.is_tab then
col = level - 1
end
if
Expand Down Expand Up @@ -203,10 +205,11 @@ local function on_win(_, winid, bufnr, toprow, botrow)
return false
end
context = { snapshot = {} }
context.step = get_shiftw_value(bufnr)
context.is_tab = not vim.bo[bufnr].expandtab
for i = toprow, botrow do
context.snapshot[i + 1] = make_snapshot(i + 1)
end
context.step = context.is_tab and vim.bo[bufnr].tabstop or get_shiftw_value(bufnr)
api.nvim_win_set_hl_ns(winid, ns)
context.leftcol = vim.fn.winsaveview().leftcol
context.count = api.nvim_buf_line_count(bufnr)
Expand Down

0 comments on commit 8cbb1b6

Please sign in to comment.