Skip to content

Commit e81cbf5

Browse files
committed
fix(diagnostic): correct cursor column calculation when cursor is at the end of a long line
1 parent c39c4af commit e81cbf5

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lua/tiny-inline-diagnostic/extmarks.lua

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ local function get_uuid()
6767
return uuid_extmark
6868
end
6969

70+
local function get_relative_position()
71+
local col = vim.fn.virtcol("$")
72+
local win_row = vim.fn.winline() - 1
73+
local leftcol = vim.fn.winsaveview().leftcol
74+
75+
return { row = win_row, col = col - leftcol }
76+
end
77+
7078
function M.create_extmarks(opts, event, curline, virt_lines, offset, need_to_be_under, virt_prorioty)
7179
local diag_overflow_last_line = false
7280
local buf_lines_count = vim.api.nvim_buf_line_count(event.buf)
@@ -76,10 +84,7 @@ function M.create_extmarks(opts, event, curline, virt_lines, offset, need_to_be_
7684
diag_overflow_last_line = true
7785
end
7886

79-
local win_col = vim.fn.virtcol({
80-
curline + 1,
81-
"$",
82-
})
87+
local win_col = get_relative_position().col
8388

8489
if need_to_be_under then
8590
win_col = 0
@@ -162,7 +167,7 @@ function M.create_extmarks(opts, event, curline, virt_lines, offset, need_to_be_
162167
line_hl_group = "TinyInlineDiagnosticVirtualTextBg",
163168
virt_text_pos = "eol",
164169
virt_text = virt_lines[1],
165-
-- virt_text_win_col = win_col + offset,
170+
virt_text_win_col = win_col,
166171
priority = virt_prorioty,
167172
strict = false,
168173
})

0 commit comments

Comments
 (0)