glacambre / firenvim

Embed Neovim in Chrome, Firefox & others.
GNU General Public License v3.0
4.65k stars 143 forks source link

Unable to resize text area #1541

Open musjj opened 1 year ago

musjj commented 1 year ago

What I tried to do

I tried to resize the text area with set lines=15. I have tried two different variations:

vim.api.nvim_create_autocmd("UIEnter", {
  callback = function()
    vim.notify("hello world!")
    vim.opt.lines = 15
  end,
})
vim.defer_fn(function()
  vim.notify("hello world!")
  vim.opt.lines = 15
end, 3000)

What happened

set lines=15 works when I set it interactively, but it simply does not work when I place any of the above two snippets into my config. They both successfully prints hello world!, but the number of lines remains unmodified.

glacambre commented 1 year ago

Hi, thanks for opening this issue. Your first code snippet is correct and the recommended way to change the dimensions of the window on startup. I copy/pasted your example in my config and it worked.

It's possible that you're encountering a timing issue. In order to confirm this, could you add

vim.api.nvim_create_autocmd("UIEnter", {
  callback = function()
    vim.fn.timer_start(3000, function()
      vim.opt.lines = 15
    end)
  end,
})

To your config and let me know if firenvim eventually gets resized (roughly 3 seconds after a start)? You might need to re-start firenvim twice in order to make sure the change to your init.lua takes effect.

musjj commented 1 year ago

Your snippet works for me, I guess this is some kind of weird race condition. I have a hard time debugging this though, because I'm not sure how to reload the config in a deterministic way. It seems that firenvim sometimes reuse nvim instances even across new tabs. Is there any way to ensure that the instance gets reloaded?

glacambre commented 1 year ago

Firenvim does not re-use neovim instances, but it pre-loads one instance at all time. So, for example, if you write A to your neovim configuration, then starts neovim, then write B to your neovim configuration, then start Firenvim, the Firenvim instance will have config A, not B. Then, if you write C to your config, close Firenvim and start Firenvim again, you will get B, because a neovim instance was pre-loaded when you started Firenvim the first time, and you had B in your config at that time.

There are two ways to ensure that you have the right config loaded in Firenvim: either start firenvim twice in a row, or use the "Reload settings" button of the Firenvim button next to your URL bar.

I would not recommend spending time on debugging your issue though. Although it is not exactly the same, this problem is in the same vein as https://github.com/glacambre/firenvim/issues/800#issuecomment-757501541 , and there is no good solution for it without changing Neovim's protocol :/