Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to eliminate the flash of an unpadded buffer? #428

Open
gregorias opened this issue Dec 25, 2024 · 7 comments · May be fixed by #429
Open

Is it possible to eliminate the flash of an unpadded buffer? #428

gregorias opened this issue Dec 25, 2024 · 7 comments · May be fixed by #429
Assignees
Labels
enhancement New feature or request in progress When an issue is being working on need investigation When an issue lack context/is not straight forward to solve

Comments

@gregorias
Copy link

gregorias commented Dec 25, 2024

Describe the problem

I have configured No Neck Pain to start on VimEnter. Even with this setting, the plugin adds padding only after a buffer and its window are loaded and displayed, e.g., when I do nvim SOME_FILE. This causes a visible flash of unpadded buffer, which, like flash of unstyled content), is unpleasant.

Describe the solution

I don’t know how to solve this, but I haven’t researched this. It would be nice if the pads could be calculated and added before the buffer is displayed.

Notes

Thank you so much for this plugin. I use it every day.

@shortcuts shortcuts linked a pull request Dec 25, 2024 that will close this issue
@shortcuts
Copy link
Owner

Hey, thanks for reporting and using the plugin :)

I currently rely on BufEnter which IIRC is one of the first event of the sequence when starting nvim, and the safest for everyone's need (e.g. if you have startup plugins like file explorers or dashboards).

Sadly most of the other events earlier in the loop (e.g. BufAdd or anything usually triggered before entering a buffer) are not available on vim startup, but I doubt they'd make humanly distinguishable changes anyway.

The only solution I see is to introduce a fast opt-in mode that is less safe but reduces the UI shift as much as possible. Would you mind trying it out from the branch?

I have configured No Neck Pain to start on VimEnter.

Just wondering, are you running your own autocmd or are you using the provided enableOnVimEnter option?

@shortcuts shortcuts self-assigned this Dec 25, 2024
@shortcuts shortcuts added enhancement New feature or request need investigation When an issue lack context/is not straight forward to solve in progress When an issue is being working on labels Dec 25, 2024
@gregorias
Copy link
Author

BufEnter might be fine, because it still happens before UIEnter. I don’t think doing things sooner should be the issue (although I’m not familiar with how NNP works).

Food for thought: I’m suspicious of any solution that relies on being “fast,” because that suggests to me that it’s asynchronous. When I start Neovim in a vsplit mode with nvim -O A B C, Neovim opens all three buffers in evenly divided windows. There’s no asynchronous adjustment of window width, the split setup happens before the windows are drawn.
Perhaps NNP could take a look on how window splits work and do something similar?

The only solution I see is to introduce a fast opt-in mode that is less safe but reduces the UI shift as much as possible. Would you mind trying it out from the branch?

I’ve tried it out, it doesn’t fix the flicker.

Just wondering, are you running your own autocmd or are you using the provided enableOnVimEnter option?

For the testing above, I did. I sort of use enableOnVimEnter, but I have a custom setup that suppresses NNP when I have the dashboard on. I found weird layout behavior if I do stuff like open a quickfix window while nvim-dashboard is on.

@gregorias gregorias changed the title Is it possible to eliminate a flash of an unpadded buffer? Is it possible to eliminate the flash of an unpadded buffer? Dec 26, 2024
@gregorias
Copy link
Author

gregorias commented Dec 29, 2024

So I found that the source of the issue is the debouncing logic. I’ve fixed the flicker by skipping debouncing like so:

vim.api.nvim_create_autocmd({ "VimEnter" }, {
  pattern = "*",
  once = true,
  callback = function()
    require("no-neck-pain.main").enable("")
  end,
})

I think that no debouncing should be the default for start-up. Debouncing only causes the layout shift.

@shortcuts
Copy link
Owner

sorry for the delay I took some time off with the holidays, and thanks for following up with more investigation!!

BufEnter might be fine, because it still happens before UIEnter. I don’t think doing things sooner should be the issue (although I’m not familiar with how NNP works).

Food for thought: I’m suspicious of any solution that relies on being “fast,” because that suggests to me that it’s asynchronous. When I start Neovim in a vsplit mode with nvim -O A B C, Neovim opens all three buffers in evenly divided windows. There’s no asynchronous adjustment of window width, the split setup happens before the windows are drawn. Perhaps NNP could take a look on how window splits work and do something similar?

The thing is that not every dashboard/file browser etc. are implemented the same way, so I had to introduce some debouncing logic to prevent race conditions with other plugins. e.g. with oil.nvim it happens that the cursor got stuck in a side buffer without the debounce, because oil highjack the first valid window encountered, so if nnp creates one first, it messes up everything.

So I found that the source of the issue is the debouncing logic. I’ve fixed the flicker by skipping debouncing like so:

Ah that make sense, I guess it messes up with the event loop even with the 2ms default that we have, even with 0 it still creates the flicker. I need to do some more tests with the other integrations

@shortcuts
Copy link
Owner

update: I can confirm that this breaks the oil.nvim support, you end up with one of the 3 following scenarios due to race conditions:

unable to determine the window:
Capture d’écran 2024-12-31 à 23 32 40

oil isn't triggered for some reason:
Capture d’écran 2024-12-31 à 23 32 50

focus on the wrong window:
Capture d’écran 2024-12-31 à 23 33 21


I can dig a bit to see if we can mitigate that but I doubt it, it might not be a sane default, however it can be opt-in

@shortcuts
Copy link
Owner

I've removed the debounce in #429 in case you'd like to experiment

@shortcuts
Copy link
Owner

oh I think I found a sane fast implementation that could be the default, it debounces only the part that recomputes the width and cursor position, so there's no flickering and it prevents the above oil bugs

I need to do more tests with other integrations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request in progress When an issue is being working on need investigation When an issue lack context/is not straight forward to solve
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants