From dc8a56ceb8a5d9712c4d6037c9d91642487394b6 Mon Sep 17 00:00:00 2001 From: tris203 Date: Sun, 16 Jun 2024 10:01:47 +0100 Subject: [PATCH] feat(precognition): add line wrapping for virtual lines This commit introduces a new feature where if the 'wrap' option is enabled and the virtual line length exceeds the window width, the virtual line is subdivided into sections. The section that contains the cursor is then displayed. --- lua/precognition/init.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lua/precognition/init.lua b/lua/precognition/init.lua index 1d00e27..995af93 100644 --- a/lua/precognition/init.lua +++ b/lua/precognition/init.lua @@ -267,6 +267,17 @@ local function display_marks() -- TODO: can we add indent lines to the virt line to match indent-blankline or similar (if installed)? + if vim.opt.wrap and #virt_line > 0 then + local width = vim.go.columns - vim.go.numberwidth - 1 + local cursorcolpos = vim.api.nvim_win_get_cursor(0)[2] + 1 + local section = math.floor(cursorcolpos / width) + local start = section * width + local end_ = start + width + if #virt_line[1][1] > width then + virt_line[1][1] = string.sub(virt_line[1][1], start, end_) + end + end + -- create (or overwrite) the extmark if config.showBlankVirtLine or (virt_line and #virt_line > 0) then extmark = vim.api.nvim_buf_set_extmark(0, ns, cursorline - 1, 0, {