oxfist / night-owl.nvim

🦉 🌌 Night Owl colorscheme implementation for Neovim with support for Treesitter and semantic tokens
BSD 3-Clause "New" or "Revised" License
250 stars 17 forks source link

When loading this theme with lazy.nvim, visual selection stops working when unfocusing and focusing back to neovim #2

Closed lampewebdev closed 1 year ago

lampewebdev commented 1 year ago

Hej,

I'm loading your theme with lazy.

When I have this theme loaded the first selection works in visual mode.

When I then un focus the window the selection is gone and selecting new text is not visible.

https://github.com/oxfist/night-owl.nvim/assets/44268468/92a0ed33-00bc-4558-ad52-59672d62849a

oxfist commented 1 year ago

@lampewebdev Thanks for reporting this issue and for providing a video! 🎉

Not quite sure what's causing this, although I have a sense on what the issue could be. This plugin creates a couple autocmds to change the Visual highlight group on FocusGained and on FocusLost:

vim.api.nvim_create_autocmd({ "FocusGained" }, {
    pattern = "*",
    command = "hi! link Visual VisualActive",
})

vim.api.nvim_create_autocmd({ "FocusLost" }, {
    pattern = "*",
    command = "hi! link Visual VisualInactive",
})

Based on what you're showing I think either something is going on with those events or something else is also changing those highlight groups.

To help debug this further can you please share the following details? I'd love to fix this for you.

  1. Which Neovim version are you running?
  2. Do you have any plugins installed that might be setting the Visual highlight group by any chance?
  3. Do you have any plugins installed that might also be creating autocmds on FocusGained or on FocusLost?
  4. What do you get when running :verbose hi Visual, :verbose hi VisualActive, and :verbose hi VisualInactive before unfocusing your terminal?
  5. What do you get when running :verbose hi Visual, :verbose hi VisualActive, and :verbose hi VisualInactive after unfocusing your terminal?
oxfist commented 1 year ago

@lampewebdev also, do you get the same issue if you disable all other themes and just enable this one?

lampewebdev commented 1 year ago

:verbose hi VisualActive
VisualActive xxx cleared

:verbose hi VisualInactive
VisualInactive xxx cleared



- What do you get when running :verbose hi Visual, :verbose hi VisualActive, and :verbose hi VisualInactive after unfocusing your terminal?
It shows the same

- do you get the same issue if you disable all other themes and just enable this one?
yes
lampewebdev commented 1 year ago

Just some things I tried:

lampewebdev commented 1 year ago

I'm pretty sure that this is the problem here https://github.com/oxfist/night-owl.nvim/blob/a6d84aa32b3708bc32397aa86b26317441bbd1d5/after/plugin/autocmds.lua#L3

Not sure how neovim works here but this code should only run when the night owl theme is active and set this back to the default option once the theme is changed.

oxfist commented 1 year ago

@lampewebdev thanks so much for your updates. I'll be able to dive into this this week and should have an update for you soon.

Just FYI, you can check the autocommands currently defined by running :autocmd FocusGained and :autocmd FocusLost. For me it shows this:

FocusGained
    *         hi! link Visual VisualActive

But I think you're on the right path, the autocommand shouldn't be set if the theme is not active. So I'll try to reproduce this and work on a fix.

lampewebdev commented 1 year ago

I only see this

:autocmd FocusGained                                                                                                     
--- Autocommands ---                                                                                                     
FocusGained                                                                                                              
    *         hi! link Visual VisualActive                                                                               
Press ENTER or type command to continue  
:autocmd FocusLost                                                                                                       
--- Autocommands ---                                                                                                     
FocusLost                                                                                                                
    *         hi! link Visual VisualInactive                                                                             
Press ENTER or type command to continue   
kmlopez-hhl commented 1 year ago

It's also messing up Lunar Vim's toggle term config, the cursor is not visible.

oxfist commented 1 year ago

@kmlopez-hhl I'm not very familiar with LunarVim, can you show me how that looks like? I'm trying to fix this and want to make sure the solution will include your setup or create a separate issue to track that separately. 🙏🏼

denisw commented 1 year ago

I'm experiencing that problem as well. Having the package loaded (Packer use) seems to be enough for this problem to happen.

denisw commented 1 year ago

@oxfist I think the issue is that the autocmd commands are in the after/ directory, which according to the Neovim docs are run when the plugin is loaded, not when the colorscheme is activated.

Perhaps you can use the ColorScheme autocmd to detect when the night-owl colorscheme gets (de)activated and use that to (un)register the FocusGained / FocusLost autocmds?

oxfist commented 1 year ago

@denisw @lampewebdev @kmlopez-hhl I was able to set the FocusGained and FocusLost highlight groups only when colorscheme is night-owl. Tested this on a minimal lazy.nvim config on my local environment and can confirm it works as expected ONLY when this theme is loaded.

Please let me know if you still have any issues! 🙏🏼

oxfist commented 1 year ago

@all-contributors please add @denisw for bug. please add @lampewebdev for bug.

allcontributors[bot] commented 1 year ago

@oxfist

@denisw already contributed before to bug

I've put up a pull request to add @lampewebdev! :tada:

oxfist commented 1 year ago

@all-contributors please add @denisw for bug

allcontributors[bot] commented 1 year ago

@oxfist

I've put up a pull request to add @denisw! :tada:

kmlopez-hhl commented 1 year ago

@oxfist thank you!

I just installed the latest, but it is still happening.

The cursor is not visible after f

Screenshot 2023-06-29 at 3 17 18 PM
oxfist commented 1 year ago

@kmlopez-hhl thanks so much for the follow-up, I created a separate issue to track that. I haven't installed toggleterm on my local environment yet but I'll reproduce the issue so I can fix it and support that plugin too.

DevanB commented 11 months ago

@oxfist I hate to possibly open up an old issue. However, I think this issue is occurring again. I don't mind opening another issue, but figured for historical purposes I'd add it here initially. I'm able to replicate the issue by using the basic kickstart.nvim (a lovely starter point from T.J.!) and replacing the color scheme block with:

{
  'oxfist/night-owl.nvim',
  lazy = false,
  priority = 1000,
  config = function()
    vim.cmd.colorscheme 'night-owl'
  end,
},

And here is the answers the questions you've asked previously:

Visual ``` :verbose hi Visual Visual xxx links to VisualActive Last set from Lua ```
VisualActive ``` :verbose hi VisualActive VisualActive xxx guibg=#1d3b53 Last set from Lua ```
VisualInactive ``` :verbose hi VisualInactive VisualInactive xxx guibg=#2e2d5e Last set from Lua ```
Visual ``` :verbose hi Visual Visual xxx links to @nowl.visual.active Last set from Lua ```
VisualActive ``` :verbose hi VisualActive VisualActive xxx guibg=#1d3b53 Last set from Lua ```
VisualInactive ``` :verbose hi VisualInactive VisualInactive xxx guibg=#2e2d5e Last set from Lua ```