From 8c07e15e0ed051d22e02e57ce185dc869cd0745e Mon Sep 17 00:00:00 2001 From: Cameron Ring Date: Thu, 24 Oct 2024 11:37:44 -0700 Subject: [PATCH 1/4] fix: #7 Show correct hl after Telescope file open --- lua/line-number-change-mode/init.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lua/line-number-change-mode/init.lua b/lua/line-number-change-mode/init.lua index 58fac17..151fd21 100644 --- a/lua/line-number-change-mode/init.lua +++ b/lua/line-number-change-mode/init.lua @@ -17,6 +17,11 @@ function M.setup(opts) vim.cmd.redraw() end end + + -- Keep track of mode because we don't get a ModeChanged event when + -- opening a file from Telescope. See: + -- https://github.com/sethen/line-number-change-mode.nvim/issues/7 + M.mode = mode end set_hl_for_mode(va.nvim_get_mode().mode) @@ -33,6 +38,24 @@ function M.setup(opts) set_hl_for_mode(new_mode) end, }) + + vim.api.nvim_create_autocmd({ "WinLeave" }, { + group = group, + callback = function(_) + -- If we're leaving a window and we're still in insert mode, schedule + -- a callback for the next run of the event loop to make sure the + -- correct mode highlight is displayed. See: + -- https://github.com/sethen/line-number-change-mode.nvim/issues/7 + if M.mode == 'i' then + vim.schedule(function() + if opts.debug then + vim.notify('in insert mode, will schedule mode set') + end + set_hl_for_mode(vim.api.nvim_get_mode().mode) + end) + end + end, + }) end return M From af708c0653f54ac50c331ca756da06a25878b79f Mon Sep 17 00:00:00 2001 From: Cameron Ring Date: Thu, 24 Oct 2024 12:08:00 -0700 Subject: [PATCH 2/4] feat: Hide inactive window cursorlines --- lua/line-number-change-mode/init.lua | 31 +++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lua/line-number-change-mode/init.lua b/lua/line-number-change-mode/init.lua index 151fd21..48b297a 100644 --- a/lua/line-number-change-mode/init.lua +++ b/lua/line-number-change-mode/init.lua @@ -39,16 +39,44 @@ function M.setup(opts) end, }) + if opts.hide_inactive_cursorline then + vim.api.nvim_create_autocmd({ "WinEnter" }, { + group = group, + callback = function(_) + local win = vim.api.nvim_get_current_win() + -- vim.notify(e.event..', win: '..win..' cl: '..vim.inspect(vim.wo.cursorline)..' had: '..vim.inspect(vim.w[win].hadcursorline)) + + -- if the cursorline was supposed to be on, turn it back on + if vim.w[win].hadcursorline and not vim.wo.cursorline then + vim.wo.cursorline = true + end + end, + }) + end + vim.api.nvim_create_autocmd({ "WinLeave" }, { group = group, callback = function(_) + if opts.hide_inactive_cursorline then + -- vim.notify(e.event..', win: '..win..' cl: '..vim.inspect(vim.wo.cursorline)..' had: '..vim.inspect(vim.w[win].hadcursorline)) + + -- If the cursorline is on, turn it off but remember that we turned it off + if vim.wo.cursorline then + local win = vim.api.nvim_get_current_win() + vim.wo.cursorline = false + vim.w[win].hadcursorline = true + + -- vim.notify('turning off cursorline for: '..win..' hadcursorline: '..vim.inspect(vim.w[win].hadcursorline)) + end + end + -- If we're leaving a window and we're still in insert mode, schedule -- a callback for the next run of the event loop to make sure the -- correct mode highlight is displayed. See: -- https://github.com/sethen/line-number-change-mode.nvim/issues/7 if M.mode == 'i' then vim.schedule(function() - if opts.debug then + if opts.debug then vim.notify('in insert mode, will schedule mode set') end set_hl_for_mode(vim.api.nvim_get_mode().mode) @@ -56,6 +84,7 @@ function M.setup(opts) end end, }) + end return M From ce2d2d5a5851ed1be2c68e72daf2b88d9794f72a Mon Sep 17 00:00:00 2001 From: Cameron Ring Date: Thu, 24 Oct 2024 12:09:24 -0700 Subject: [PATCH 3/4] docs(README): describe hide_inactive_cursorline --- README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 94ecf7d..c4a5903 100644 --- a/README.md +++ b/README.md @@ -46,12 +46,28 @@ return { fg = palette.mantle, bold = true, }, - } + }, + hide_inactive_cursorline = false, }) end } ``` +## Hiding inactive cursorlines + +It's off by defaut, but if you set `hide_inactive_cursorline = true`, then this plugin will hide the cursorline for inactive windows so the mode highlight will only be shown in the currently active window: + + +Note: if you're lazy loading this plugin and want to hide inactive window cursorlines, make sure `event` is either set to `VeryLazy` or as follows: + +```lua +return { + 'sethen/line-number-change-mode.nvim', + event = { 'ModeChanged', 'WinEnter', 'WinLeave' }, +... +} +``` + # Similar Plugins ❤️ * [Moody](https://github.com/svampkorg/moody.nvim) * [Modicator](https://github.com/mawkler/modicator.nvim) From 09bbd371d9dcbf2a298ebb8ddde0dc3f6a95e6ec Mon Sep 17 00:00:00 2001 From: Cameron Ring Date: Thu, 24 Oct 2024 12:19:08 -0700 Subject: [PATCH 4/4] docs(README): screenshot Screenshot for `hide_inactive_cursorline` --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c4a5903..c1d191f 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ return { It's off by defaut, but if you set `hide_inactive_cursorline = true`, then this plugin will hide the cursorline for inactive windows so the mode highlight will only be shown in the currently active window: +![Screenshot 2024-10-24 at 12 16 58](https://github.com/user-attachments/assets/2286df66-af72-43e7-b4fc-305f696ad206) Note: if you're lazy loading this plugin and want to hide inactive window cursorlines, make sure `event` is either set to `VeryLazy` or as follows: