From 396893ae53dde3968699cdf8ff3565d631409344 Mon Sep 17 00:00:00 2001 From: chickiexd Date: Tue, 13 May 2025 15:51:07 +0200 Subject: [PATCH] feat(highlight): allow disabling highlighting feat(highlight): allow disabling highlighting yes --- README.md | 1 + lua/todo-comments/config.lua | 1 + lua/todo-comments/highlight.lua | 46 +++++++++++++++++---------------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 06c1022..20bdd24 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ Todo comes with the following defaults: -- * keyword: highlights of the keyword -- * after: highlights after the keyword (todo text) highlight = { + enable = true, -- enable highlighting multiline = true, -- enable multine todo comments multiline_pattern = "^.", -- lua pattern to match the next multiline from the start of the matched keyword multiline_context = 10, -- extra lines that will be re-evaluated when changing a line diff --git a/lua/todo-comments/config.lua b/lua/todo-comments/config.lua index 0e2d34e..16d3186 100644 --- a/lua/todo-comments/config.lua +++ b/lua/todo-comments/config.lua @@ -40,6 +40,7 @@ local defaults = { -- * keyword: highlights of the keyword -- * after: highlights after the keyword (todo text) highlight = { + enable = true, -- enable highlighting multiline = true, -- enable multine todo comments multiline_pattern = "^.", -- lua pattern to match the next multiline from the start of the matched keyword multiline_context = 10, -- extra lines that will be re-evaluated when changing a line diff --git a/lua/todo-comments/highlight.lua b/lua/todo-comments/highlight.lua index 7a3d4e0..68a5857 100644 --- a/lua/todo-comments/highlight.lua +++ b/lua/todo-comments/highlight.lua @@ -214,31 +214,33 @@ function M.highlight(buf, first, last, _event) local hl = Config.options.highlight - if not is_multiline then - -- before highlights - if hl.before == "fg" then - add_highlight(buf, Config.ns, hl_fg, lnum, 0, start) - elseif hl.before == "bg" then - add_highlight(buf, Config.ns, hl_bg, lnum, 0, start) - end + if hl.enable then + if not is_multiline then + -- before highlights + if hl.before == "fg" then + add_highlight(buf, Config.ns, hl_fg, lnum, 0, start) + elseif hl.before == "bg" then + add_highlight(buf, Config.ns, hl_bg, lnum, 0, start) + end - -- tag highlights - if hl.keyword == "wide" or hl.keyword == "wide_bg" then - add_highlight(buf, Config.ns, hl_bg, lnum, math.max(start - 1, 0), finish + 1) - elseif hl.keyword == "wide_fg" then - add_highlight(buf, Config.ns, hl_fg, lnum, math.max(start - 1, 0), finish + 1) - elseif hl.keyword == "bg" then - add_highlight(buf, Config.ns, hl_bg, lnum, start, finish) - elseif hl.keyword == "fg" then - add_highlight(buf, Config.ns, hl_fg, lnum, start, finish) + -- tag highlights + if hl.keyword == "wide" or hl.keyword == "wide_bg" then + add_highlight(buf, Config.ns, hl_bg, lnum, math.max(start - 1, 0), finish + 1) + elseif hl.keyword == "wide_fg" then + add_highlight(buf, Config.ns, hl_fg, lnum, math.max(start - 1, 0), finish + 1) + elseif hl.keyword == "bg" then + add_highlight(buf, Config.ns, hl_bg, lnum, start, finish) + elseif hl.keyword == "fg" then + add_highlight(buf, Config.ns, hl_fg, lnum, start, finish) + end end - end - -- after highlights - if hl.after == "fg" then - add_highlight(buf, Config.ns, hl_fg, lnum, finish, #line) - elseif hl.after == "bg" then - add_highlight(buf, Config.ns, hl_bg, lnum, finish, #line) + -- after highlights + if hl.after == "fg" then + add_highlight(buf, Config.ns, hl_fg, lnum, finish, #line) + elseif hl.after == "bg" then + add_highlight(buf, Config.ns, hl_bg, lnum, finish, #line) + end end if not is_multiline then