Skip to content

Commit

Permalink
toggeling cursorcross switches it off only when both cursorline and c…
Browse files Browse the repository at this point in the history
…ursorcolumn is turned on
  • Loading branch information
tummetott committed Jan 25, 2023
1 parent f78d7a5 commit d91453c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lua/unimpaired/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,19 @@ M.enable_cursorline = function() vim.o.cursorline = true end

M.disable_cursorline = function() vim.o.cursorline = false end

M.toggle_cursorline = function()
local get_cursorline_value = function()
-- The plugin reticle.nvim has an option to always show the cursorline
-- number, even when the cursorline itself is not enabled. This requires the
-- cursorline setting to remain switched on. Therefore we can't get the
-- cursorline state from the option itself, we load it from the plugin
-- cursorline state from the option itself but we can get in from the
-- plugin. Lets' create a wrapper function around getting this option
local loaded, reticle = pcall(require, 'reticle')
if loaded then vim.o.cursorline = not reticle.enabled.cursorline
else vim.o.cursorline = not vim.o.cursorline end
if loaded then return reticle.enabled.cursorline
else return vim.o.cursorline end
end

M.toggle_cursorline = function() vim.o.cursorline = not get_cursorline_value() end

M.enable_diff = function() vim.cmd('diffthis') end

M.disable_diff = function() vim.cmd('diffoff') end
Expand Down Expand Up @@ -330,8 +333,11 @@ M.disable_cursorcross = function()
end

M.toggle_cursorcross = function()
if vim.o.cursorcolumn then M.disable_cursorcross()
else M.enable_cursorcross() end
if get_cursorline_value() and vim.o.cursorcolumn then
M.disable_cursorcross()
else
M.enable_cursorcross()
end
end

local autocmd = vim.api.nvim_create_autocmd
Expand Down

0 comments on commit d91453c

Please sign in to comment.