levouh/tint.nvim

Strange issue ignoring diff windows

hbiel opened this issue · 4 comments

hbiel commented

Hey @levouh!

I wanted to exclude diffview from being tinted and came across some strange behaviour.

For identifying the diff windows i wanted to evaluate the option 'diff' which is true on those windows.
This does not work though (or at least in my case). The windows are still being tinted and they won't even untint when entering the windows anymore.

This is my current configuration:

require("tint").setup({
    tint = -50,
    saturation = 0.5,
    window_ignore_function = function(winid)
        local bufid = vim.api.nvim_win_get_buf(winid)

        local ignoredFiletypes = { "DiffviewFiles", "DiffviewFileHistory" }
        local ignoredBuftypes  = { "terminal" }

        local isDiff = vim.api.nvim_win_get_option(winid, "diff")
        local isFloating = vim.api.nvim_win_get_config(winid).relative ~= ""
        local isIgnoredBuftype  = vim.tbl_contains(ignoredBuftypes, vim.api.nvim_buf_get_option(bufid, "buftype"))
        local isIgnoredFiletype = vim.tbl_contains(ignoredFiletypes, vim.api.nvim_buf_get_option(bufid, "filetype"))

        return isDiff or isFloating or isIgnoredBuftype or isIgnoredFiletype
    end
})

Adding this block makes it work but feels kinda redundant since it shouldn't be tinted in the first place:

        if(isDiff) then
            require("tint").untint(winid)
        end

Is this reproduceable for you?

Best regards!

Have you done any debugging to ensure that your require("tint").untint(winid) actually gets called by chance @hbiel? I am curious if it is a timing issue where the window is not recognized correctly, or if it is an issue with the untint function itself.

hbiel commented

I have not done any advanced debugging. I only had prints for my variables to verify if they evaluate to true.

Just to make sure: using the mentioned block and calling untint in the window_ignore_function does work as intended and is my current solution. I was just wondering if this should be even needed since the diff windows are to be ignored and shouldn't be tinted in the first place.

But maybe the diff option gets set only after the windows have already been tinted. That might also be why they don't get untinted on enter since the windows are now being ignored correctly. I have not verified this either though. It's just a hunch I got.

Anyway, my current solution is good enough for me. I just wanted to bring this to your attention and maybe get some input if I did something wrong.

I have something similar in my own setup due to (seemingly) the way that some window options get applied with a delay. tint runs on Win{Enter,Leave} (and realistically any other events that you configure), and as you pointed out, this appears too early for when Diff* highlights are setup. Rather than add some arbitrary delay or try to handle events like this "natively", I figured just allowing the user to handle it on their own would be better.

If the solution you've setup works for you, I think we are good to go. I appreciate you noting it here, but I'm not sure there is actually anything that can be done about it in a "clean" way here.

hbiel commented

Sure that's fine by me. Thank you for taking your time looking into this and working on this plugin!

For future users a compilation of known edge cases and possible solutions might be helpful. Could be either in the wiki or a section in the readme. Just a thought.