Skip to content

Experimental cursor highlighting support #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions lua/colorizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,49 @@ local function get_buffer_options(buf)
return merge({}, BUFFER_OPTIONS[buf])
end

nvim.o.guicursor = "n-v-c-sm:block-Cursor,i-ci-ve:ver25,r-cr-o:hor20"
local CURSOR_HIGHLIGHTS
local CURSOR_LINE
local function follow_cursor()
local pos = nvim.win_get_cursor(0)
local buf = nvim_get_current_buf()
local options = BUFFER_OPTIONS[buf]
if not options then return end

if pos[1] ~= CURSOR_LINE then
CURSOR_LINE = pos[1]
CURSOR_HIGHLIGHTS = {}
local line = nvim_buf_get_lines(buf, CURSOR_LINE-1, CURSOR_LINE, true)[1]
local loop_parse_fn = make_matcher(options)
local i = 1
while i < #line do
local length, rgb_hex = loop_parse_fn(line, i)
if length then
table.insert(CURSOR_HIGHLIGHTS, {i, i+length, rgb_hex})
i = i + length
else
i = i + 1
end
end
end
local col = pos[2]+1
local highlight_found = false
for _, highlight in ipairs(CURSOR_HIGHLIGHTS) do
local i, j, rgb_hex = unpack(highlight)
if i <= col and j > col then
print(col, i, j, rgb_hex)
nvim.ex.highlight("Cursor", "guibg=#"..rgb_hex, "guifg=#"..rgb_hex)
highlight_found = true
break
end
end
if not highlight_found then
nvim.ex.highlight("Cursor NONE")
end
end
FOLLOW_CURSOR = follow_cursor
nvim.ex.autocmd("CursorMoved,CursorMovedI * lua FOLLOW_CURSOR()")

--- @export
return {
DEFAULT_NAMESPACE = DEFAULT_NAMESPACE;
Expand Down