Skip to content

Commit

Permalink
Merge pull request #11 from TheFunctionalGuy/fix-cursor-behavior
Browse files Browse the repository at this point in the history
Update colorcolumn value only when state changed
  • Loading branch information
m4xshen authored Mar 21, 2023
2 parents 6e16c7d + 531c68f commit 0c572e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions lua/smartcolumn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0c572e3

Please sign in to comment.