From fb4f7c2845632d6c924add4586b6ee37818ce1d5 Mon Sep 17 00:00:00 2001 From: glepnir Date: Tue, 29 Oct 2024 17:26:58 +0800 Subject: [PATCH] fix: skip wrapped line --- lua/indentmini/init.lua | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lua/indentmini/init.lua b/lua/indentmini/init.lua index 54e396f..33ebb47 100644 --- a/lua/indentmini/init.lua +++ b/lua/indentmini/init.lua @@ -163,12 +163,24 @@ local function find_current_range(currow_indent) or math.floor(currow_indent / context.step) end -local function on_line(_, _, bufnr, row) +local function is_wrapped_line(winid, lnum) + if not vim.wo[winid].wrap then + return false + end + local win_width = api.nvim_win_get_width(0) + local virtcol = vim.fn.virtcol({ lnum, '$' }) + return virtcol > win_width and true or false +end + +local next_is_wrap = false + +local function on_line(_, winid, bufnr, row) local sp = find_in_snapshot(row + 1) - if sp.indent == 0 or out_current_range(row) then + if sp.indent == 0 or out_current_range(row) or next_is_wrap then + next_is_wrap = false return end - -- mixup like vim code has shebang vi:set ts=8 sts=4 sw=4 noet: + -- mixup like vim code has modeline vi:set ts=8 sts=4 sw=4 noet: -- 4 8 12 16 20 24 -- 1 1 2 2 3 3 local total = context.mixup and math.ceil(sp.indent / context.tabstop) or sp.indent - 1 @@ -201,6 +213,7 @@ local function on_line(_, _, bufnr, row) opt.config.virt_text_win_col = nil end end + next_is_wrap = is_wrapped_line(winid, row + 1) end local function on_win(_, winid, bufnr, toprow, botrow) @@ -237,7 +250,7 @@ return { setup = function(conf) conf = conf or {} opt.only_current = conf.only_current or false - opt.exclude = { 'dashboard', 'lazy', 'help', 'markdown', 'nofile', 'terminal', 'prompt' } + opt.exclude = { 'dashboard', 'lazy', 'help', 'nofile', 'terminal', 'prompt' } vim.list_extend(opt.exclude, conf.exclude or {}) opt.config.virt_text = { { conf.char or '│' } } opt.minlevel = conf.minlevel or 1