mvllow / modes.nvim

Prismatic line decorations for the adventurous vim user
550 stars 13 forks source link

Ignore_filetypes fails for mode changes inside ignored file #28

Closed PriceHiller closed 2 years ago

PriceHiller commented 2 years ago

Description

I use neo-tree for my file browser and recently noticed that the fuzzy_search functionality in it, when combined with modes.nvim, leaves my cursorline invisible in insert mode. The cursorline works as expected when I disable modes.nvim. My config has neo-tree & the neo-tree-popup in the ignore_filetypes and I still am getting an invisible cursorline in the fuzzy_search mode.

My relevant modes config:

local modes = require('modes')
modes.setup({
    colors = {
        visual = '#F959FF',
    },
    ignore_filetypes = {
        'neo-tree',
        'neo-tree-popup',
        'TelescopePrompt',
    },
})

Here's a gif of the bug in action: NTInvisible

Here's a gif with modes removed & neo-tree working as expected: NTCorrect

Potential Fix

It's 100% related to this single nvim_autocmd, when I remove it, the plugin works mostly as expected:

vim.api.nvim_create_autocmd('WinLeave', {
    pattern = '*',
    callback = M.disable_managed_ui,
})

Solution One

A fix would be to change the pattern to only act on non-excluded filetypes, or just live with the fact that it's going to highlight the other windows. I'm not sure what a proper fix to this is, but it makes it very difficult to use neo-tree.

The reason this occurs is because when a switch happens to the fuzzy finder, it invokes a WinLeave event which this then catches and disables the cursorline for, disabling the ability to actively browse the file tree with the search window up.

When I state mostly, there is also an issue with the insertenter not respecting the filetype beneath because it's setting the cursorline green when really it's just a picker.

Solution Two

The other way to fix this is to remove this single section in disable_managed_ui:

if config.set_cursorline then
    vim.opt.cursorline = false
end

When the above is removed it also works mostly as expected.

A potential way to "fix" this is to make a note of it in the docs and mention setting the cursorline to false in the setup and setting vim.opt.cursorline = true elsewhere by the user.

Solution Three

In the modes.nvim setup function, passing set_cursorline = false then setting vim.opt.cursorline = true elsewhere in the configuration works, but exited windows still keep their cursorlines as modes is no longer managing the WinLeave events to disable the cursorline.

mvllow commented 2 years ago

I'm not sure if this is possible – we disable the cursorline for inactive windows so that they are not highlighted by modes. In the linked PR, I tried using just highlights instead of toggling vim.opt.cursorline but in plugins like NvimTree, if you are changing text in a buffer the cursorline in NvimTree will change colours to match (not desirable).

I'm curious if removing any combination of neo-tree/neo-tree-popup from ignored filetypes would give you a better experience?

PriceHiller commented 2 years ago

The only way I see this as being possible with desirable behavior is if there is a way we can see what window the WinLeave event is heading to. For instance, I begin the fuzzy search and the WinLeave event function can check if the window being left to is neo-tree-popup and then keep the cursorline, if not then remove it.

Imo – I think I can live with having the cursorline managed and on-screen in multiple windows for now, I don't know a great fix to this that keeps the same behavior and keeps it simple to set up modes from a user perspective.

I'm curious if removing any combination of neo-tree/neo-tree-popup from ignored filetypes would give you a better experience?

No luck I'm afraid. Tried a bunch of combos and played around with ftplugin, but I still don't get desirable behavior 😔. Primary core of the problem for it is detecting what window is being left to, that would be the best way to resolve this.

mvllow commented 2 years ago

On another note, maybe neo-tree has a way to change search match highlights?

PriceHiller commented 2 years ago

Neo-tree does not unfortunately, I have a working solution for myself currently, but I do get cursorlines in windows I'm not in. This is a more fundamental problem to my eyes, not something that can be trivially solved and still maintain all desired functionality across all use cases.

mvllow commented 2 years ago

This is interesting https://github.com/neovim/neovim/issues/18500

mvllow commented 2 years ago

Closing as I don't have a good solution for this. PR's are welcome 😌

fitrh commented 2 years ago

@treatybreaker can you try the latest version of modes.nvim to confirm if this issue still exists ? with and without ignore_filetypes

PriceHiller commented 2 years ago

@fitrh Only just saw this now, it still does not work unfortunately. I gave it a shot myself previously to resolve this, but the problem is more fundamental and has to do with how neo-tree handles its own cursor highlights and missing features in the neovim api. At least, that's my understanding.

fitrh commented 2 years ago

@treatybreaker how to reproduce your issue ? I never use neo-tree