Skip to content

Commit

Permalink
perf(colors): update color at cursor on CursorMoved
Browse files Browse the repository at this point in the history
  • Loading branch information
folke authored and sphamba committed Nov 29, 2024
1 parent 912084f commit 5f0faf1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lua/smear_cursor/color.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ local function get_hl_color(group, attr)
end

local cursor_color = nil
local color_at_cursor = nil
local normal_bg = nil
local transparent_bg_fallback_color = "#303030"
local cache = {} ---@type table<string, boolean>
Expand Down Expand Up @@ -65,6 +66,13 @@ function M.get_color_at_cursor()
end
end

function M.update_color_at_cursor()
if cursor_color ~= "none" then
return
end
color_at_cursor = M.get_color_at_cursor()
end

---@param opts? {level?: number, inverted?: boolean}
function M.get_hl_group(opts)
opts = opts or {}
Expand All @@ -75,7 +83,7 @@ function M.get_hl_group(opts)
-- Get the cursor color from the treesitter highlight group
-- at the cursor.
if cursor_color == "none" then
_cursor_color = M.get_color_at_cursor()
_cursor_color = color_at_cursor
if _cursor_color then
hl_group = hl_group .. "_" .. _cursor_color:sub(2)
end
Expand Down
1 change: 1 addition & 0 deletions lua/smear_cursor/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ M.listen = function()
[[
augroup SmearCursor
autocmd!
autocmd CursorMoved,CursorMovedI * lua require("smear_cursor.color").update_color_at_cursor()
autocmd CursorMoved * lua require("smear_cursor.events").move_cursor()
autocmd CursorMovedI,WinScrolled * lua require("smear_cursor.events").jump_cursor()
autocmd BufLeave * lua require("smear_cursor.events").flag_switching_buffer()
Expand Down

0 comments on commit 5f0faf1

Please sign in to comment.