diff --git a/README.md b/README.md index e516687..acdc97b 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ The available options: - `{ "80", "100" }` - `disabled_filetypes` (table of strings) : the `colorcolumn` will be disabled under the filetypes in this table - `{ "help", "text", "markdown" }` (default) - - `{ "NvimTree", "Lazy", "mason", "help" }` + - `{ "NvimTree", "lazy", "mason", "help" }` - `scope` (strings): the plugin only checks whether the lines within scope exceed colorcolumn - `"file"` (default): current file - `"window"`: visible part of current window diff --git a/lua/smartcolumn.lua b/lua/smartcolumn.lua index 85566ad..3b55c7e 100644 --- a/lua/smartcolumn.lua +++ b/lua/smartcolumn.lua @@ -54,14 +54,18 @@ local function update() for _, win in pairs(wins) do local buf = vim.api.nvim_win_get_buf(win) if buf == current_buf then - if exceed(buf, win, min_colorcolumn) then - if type(colorcolumns) == "table" then - vim.wo[win].colorcolumn = table.concat(colorcolumns, ",") + local current_state = exceed(buf, win, min_colorcolumn) + if current_state ~= vim.b.prev_state then + vim.b.prev_state = current_state + if current_state then + if type(colorcolumns) == "table" then + vim.wo[win].colorcolumn = table.concat(colorcolumns, ",") + else + vim.wo[win].colorcolumn = colorcolumns + end else - vim.wo[win].colorcolumn = colorcolumns + vim.wo[win].colorcolumn = nil end - else - vim.wo[win].colorcolumn = nil end end end