Skip to content

Commit b6f844a

Browse files
committed
feat(plugins): replace local-highlight with mini.cursorword
1 parent bd22b62 commit b6f844a

File tree

5 files changed

+41
-16
lines changed

5 files changed

+41
-16
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
return function()
2+
require("mini.cursorword").setup({
3+
-- Delay (in ms) between when cursor moved and when highlighting appeared
4+
delay = 200,
5+
})
6+
require("modules.utils").gen_cursorword_hl()
7+
end

lua/modules/configs/editor/local-highlight.lua

Lines changed: 0 additions & 9 deletions
This file was deleted.

lua/modules/configs/ui/catppuccin.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ return function()
4141
gitsigns = true,
4242
grug_far = true,
4343
hop = false,
44-
illuminate = true,
4544
indent_blankline = { enabled = true, colored_indent_levels = true },
4645
lsp_saga = true,
4746
lsp_trouble = true,

lua/modules/plugins/editor.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ editor["echasnovski/mini.align"] = {
3636
event = { "CursorHold", "CursorHoldI" },
3737
config = require("editor.align"),
3838
}
39+
editor["echasnovski/mini.cursorword"] = {
40+
lazy = true,
41+
event = { "BufReadPost", "BufAdd", "BufNewFile" },
42+
config = require("editor.cursorword"),
43+
}
3944
editor["echasnovski/mini.surround"] = {
4045
lazy = true,
4146
event = { "CursorHold", "CursorHoldI" },
@@ -83,11 +88,6 @@ editor["romainl/vim-cool"] = {
8388
lazy = true,
8489
event = { "CursorMoved", "InsertEnter" },
8590
}
86-
editor["tzachar/local-highlight.nvim"] = {
87-
lazy = true,
88-
event = { "BufReadPost", "BufAdd", "BufNewFile" },
89-
config = require("editor.local-highlight"),
90-
}
9191
editor["brenoprata10/nvim-highlight-colors"] = {
9292
lazy = true,
9393
event = { "CursorHold", "CursorHoldI" },

lua/modules/utils/init.lua

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ end
104104
-- NOTE: If the active colorscheme isn't `catppuccin`, this function won't overwrite existing definitions
105105
---Sets a global highlight group.
106106
---@param name string @Highlight group name, e.g. "ErrorMsg"
107-
---@param foreground string @The foreground color
107+
---@param foreground? string @The foreground color
108108
---@param background? string @The background color
109109
---@param italic? boolean
110110
local function set_global_hl(name, foreground, background, italic)
@@ -134,6 +134,24 @@ function M.blend(foreground, background, alpha)
134134
return string.format("#%02x%02x%02x", blend_channel(1), blend_channel(2), blend_channel(3))
135135
end
136136

137+
---Darken a color by blending it with the background color.
138+
---@param hex string @The color in hex to darken
139+
---@param amount number @The amount to darken the color
140+
---@param bg string @The background color to blend with
141+
---@return string @The darkened color as a hex string
142+
function M.darken(hex, amount, bg)
143+
return M.blend(hex, bg or "#000000", math.abs(amount))
144+
end
145+
146+
---Lighten a color by blending it with the foreground color.
147+
---@param hex string @The color in hex to lighten
148+
---@param amount number @The amount to lighten the color
149+
---@param fg string @The foreground color to blend with
150+
---@return string @The lightened color as a hex string
151+
function M.lighten(hex, amount, fg)
152+
return M.blend(hex, fg or "#FFFFFF", math.abs(amount))
153+
end
154+
137155
---Get RGB highlight by highlight group
138156
---@param hl_group string @Highlight group name
139157
---@param use_bg boolean @Returns background or not
@@ -170,6 +188,7 @@ function M.extend_hl(name, def)
170188
local current_def = vim.api.nvim_get_hl(0, { name = name, link = false })
171189
local combined_def = vim.tbl_deep_extend("force", current_def, def)
172190

191+
---@diagnostic disable-next-line: param-type-mismatch
173192
vim.api.nvim_set_hl(0, name, combined_def)
174193
end
175194

@@ -239,6 +258,15 @@ function M.gen_alpha_hl()
239258
set_global_hl("AlphaFooter", colors.yellow)
240259
end
241260

261+
-- Generate highlight groups for cursorword. Existing attributes will NOT be overwritten
262+
function M.gen_cursorword_hl()
263+
local colors = M.get_palette()
264+
265+
-- Do not highlight `MiniCursorwordCurrent`
266+
set_global_hl("MiniCursorword", nil, M.darken(colors.surface1, 0.7, colors.base))
267+
set_global_hl("MiniCursorwordCurrent", nil)
268+
end
269+
242270
---Convert number (0/1) to boolean
243271
---@param value number @The value to check
244272
---@return boolean|nil @Returns nil if failed

0 commit comments

Comments
 (0)