mikavilpas / yazi.nvim

A Neovim Plugin for the yazi terminal file manager
MIT License
243 stars 7 forks source link

fix: use explicit buffer id to ensure the behavior of 'winleave' auto… #37

Closed isvicy closed 2 months ago

isvicy commented 2 months ago

mainly fixes #36

in my case, there are two problems i met:

图片

mikavilpas commented 2 months ago

Thanks, I think this is a good idea. I think it might need a bit more before it can be merged: I noticed that if I click outside of the yazi modal, the window stays up but its contents (yazi in the terminal) are now killed.

I don't think many people will have this issue, but it would be easier for me to solve that at the same time as this. I will do some more testing hopefully today.

mikavilpas commented 2 months ago

Note to myself: also there seem to be some issues when opening a file in a new split with this change. It can probably be solved though.

mikavilpas commented 2 months ago

Ok I refactored the window implementation a bit. Now it should try to safely close when focus is lost - previously I guess sometimes one of the buffers was already closed due to your other plugin having its own autocommands (not really sure)

Can you try this implementation out?

mikavilpas commented 2 months ago

Ah never mind, it doesn't work yet. Let me try again.

mikavilpas commented 2 months ago

Oh it actually does work, the reproduction file just ran the unfixed code. Here's an updated one that targets this branch (in your fork). You might be able to automatically update it with nvim -u repro.lua -c "lua require('lazy').update()". If that doesn't work then you have to call :Lazy and use the ui to Update, etc.

Details

```lua -- DO NOT change the paths and don't remove the colorscheme local root = vim.fn.fnamemodify('./.repro', ':p') -- set stdpaths to use .repro for _, name in ipairs({ 'config', 'data', 'state', 'cache' }) do vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name end -- bootstrap lazy local lazypath = root .. '/plugins/lazy.nvim' if not vim.loop.fs_stat(lazypath) then vim.fn.system({ 'git', 'clone', '--filter=blob:none', 'https://github.com/folke/lazy.nvim.git', lazypath, }) end vim.opt.runtimepath:prepend(lazypath) vim.g.mapleader = ' ' -- install plugins local plugins = { 'folke/tokyonight.nvim', { 'ak2kay/yazi.nvim', branch = 'fix-window', dependencies = { 'nvim-lua/plenary.nvim', }, event = 'VeryLazy', keys = { { -- 👇 choose your own keymapping 'fy', function() require('yazi').yazi() end, { desc = 'Open the file manager' }, }, }, opts = { open_for_directories = false, }, }, { 'zbirenbaum/nvterm', opts = {} }, } require('lazy').setup(plugins, { root = root .. '/plugins', }) vim.cmd.colorscheme('tokyonight') -- add anything else here ```

isvicy commented 2 months ago

That's very kind and nice of you!

I can confirm my config is working as expected with your refactoring.

mikavilpas commented 2 months ago

Awesome! It was a great excuse to refactor a bit. Plus, I think the reproduction environment will be useful in the future 👍🏻