From 0e27a1b647c271fcf4d04d9db47e5b42c0b91b8f Mon Sep 17 00:00:00 2001 From: ADoyle Date: Thu, 8 Sep 2022 12:34:50 +0800 Subject: [PATCH] fix: plugin not work when colors are more than termcolors If you defined `{colors = { "#cc241d", "#a89984" }, termcolors = {}}`, you can't reproduce the issue. Because there are seven colors and termcolors in default config. If you defined colors more than seven, colors = { "#cc241d", "#a89984", "#b16286", "#d79921", "#689d6a", "#d65d0e", "#458588", "#005f87" }, termcolors = {}, Or colors' length more than termcolors', colors = { "#cc241d", "#a89984"}, termcolors = { 3 }, then the issue can be reproduced. close #120 --- lua/rainbow/internal.lua | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lua/rainbow/internal.lua b/lua/rainbow/internal.lua index b59c33c..074d1df 100644 --- a/lua/rainbow/internal.lua +++ b/lua/rainbow/internal.lua @@ -89,10 +89,10 @@ local function update_range(bufnr, changes, tree, lang) { startRow, startCol }, { endRow, endCol - 1 }, { - regtype = "b", - inclusive = true, - priority = 210, - } + regtype = "b", + inclusive = true, + priority = 210, + } ) else vim.highlight.range( @@ -156,14 +156,9 @@ local M = {} --- Define highlight groups. This had to be a function to allow an autocmd doing this at colorscheme change. function M.defhl() + local set_hl = vim.api.nvim_set_hl for i = 1, #colors do - local s = string.format( - "highlight default rainbowcol%d guifg=%s ctermfg=%s", - i, - colors[i], - termcolors[i] - ) - vim.cmd(s) + set_hl(0, 'rainbowcol' .. i, { fg = colors[i], ctermfg = termcolors[i] }) end end