From 59ce465f6d51f1d3b8ae18a3346264006e99aab5 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sun, 8 Jun 2025 11:09:30 -0500 Subject: fix the line number detection with tabs If a line includes tabs add the visually added space for each tab stop to the line length in order to detect a wrapped line. --- init.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index fd8c0b4..498887d 100644 --- a/init.lua +++ b/init.lua @@ -566,9 +566,14 @@ local function file_lineno_to_viewport_lineno(win, file_lineno) local view_lineno = 0 for n = win.viewport.lines.start, file_lineno do view_lineno = view_lineno + 1 - -- Wrapped line this shifts our displayed line down - if #win.file.lines[n] > win.viewport.width then - view_lineno = view_lineno + math.floor(#win.file.lines[n] / win.viewport.width) + -- Wrapped lines shift our displayed line down + local line_len = #win.file.lines[n] + if not win.options.expandtab then + line_len = util.visual_chars_in_line(win, win.file.lines[n], line_len) + end + + if line_len >= win.viewport.width then + view_lineno = view_lineno + math.floor(line_len / win.viewport.width) end end return view_lineno -- cgit v1.2.3