Skip to content

Commit

Permalink
feat(precognition): add line wrapping for virtual lines
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tris203 committed Jun 16, 2024
1 parent 7a76d43 commit 4af62eb
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lua/precognition/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit 4af62eb

Please sign in to comment.