shortcuts / no-neck-pain.nvim

☕ Dead simple yet super extensible plugin to center the currently focused buffer to the middle of the screen.
MIT License
596 stars 14 forks source link

[bug]: need to do killAllBuffersOnDisable three times #420

Open ilan-schemoul opened 2 days ago

ilan-schemoul commented 2 days ago

Description

killAllBuffersOnDisable = true I have two windows. I do z one time nothing happens. Second time right pane is closed. Third time I enter finally in NoNeckPain mode (window centered).

https://asciinema.org/a/PjILOtkDcZofOs1rp4RxLdG9g

Neovim version

0.9.x

Steps to reproduce

Lazy config

return {
  "shortcuts/no-neck-pain.nvim",
  init = function()
    vim.api.nvim_create_autocmd("FileType", {
      pattern = "no-neck-pain",
      callback = function()
        vim.b.focus_disable = true
        vim.b.nonumber = 1;
      end
    })
  end,
  opts = {
    killAllBuffersOnDisable = true,
  },
  keys = {
    { "<leader>z", "<Cmd>NoNeckPain<CR>" }
  },
}

My repo

Relevant log output

:messages
W325: Ignoring swapfile from Nvim process 1587548
[no-neck-pain.nvim@public_api_toggle] >> debouncer triggered
[no-neck-pain.nvim@public_api_toggle] calling enable for tab 1
[no-neck-pain.nvim@set_tab] registered new tab 1
[no-neck-pain.nvim@public_api_toggle] computed columns: 0 - 2
[no-neck-pain.nvim@public_api_toggle] init called on tab 1 for current window 1000
[no-neck-pain.nvim@get_side_width:left] 0/180 after integrations - 2 columns remaining
[no-neck-pain.nvim@get_side_width:left] 200/180 - no space left to create side
[no-neck-pain.nvim@get_side_width:right] 0/180 after integrations - 2 columns remaining
[no-neck-pain.nvim@get_side_width:right] 200/180 - no space left to create side
[no-neck-pain.nvim@public_api_toggle] computed columns: 2 - 2
[no-neck-pain.nvim@public_api_toggle] >> debouncer triggered
[no-neck-pain.nvim@public_api_toggle] calling disable for tab 1
[no-neck-pain.nvim@public_api_toggle] refreshing tabs...
[no-neck-pain.nvim@public_api_toggle] no more active tabs left, reinitializing state
[no-neck-pain.nvim@public_api_toggle] >> debouncer triggered
[no-neck-pain.nvim@public_api_toggle] calling enable for tab 1
[no-neck-pain.nvim@set_tab] registered new tab 1
[no-neck-pain.nvim@public_api_toggle] computed columns: 0 - 1
[no-neck-pain.nvim@public_api_toggle] init called on tab 1 for current window 1000
[no-neck-pain.nvim@get_side_width:left] 0/180 after integrations - 1 columns remaining
[no-neck-pain.nvim@get_side_width:left] 100/180 after splits - final 40
[no-neck-pain.nvim@get_side_width:right] 0/180 after integrations - 1 columns remaining
[no-neck-pain.nvim@get_side_width:right] 100/180 after splits - final 40
[no-neck-pain.nvim@colors.init] skipping color initialization for side left
[no-neck-pain.nvim@colors.init] skipping color initialization for side right
[no-neck-pain.nvim@left] resizing 1011 with padding 40
[no-neck-pain.nvim@right] resizing 1012 with padding 40
[no-neck-pain.nvim@public_api_toggle] rerouting focus of 1012 to

Self-service

ilan-schemoul commented 2 days ago

Also is there a way to restore closed windows after leaving NoNeckPain mode

ilan-schemoul commented 1 day ago

I think the problem is the code vim.cmd("only") is called in main.disable instead of main.enable.

However once I do that fix I have another problem: the layout is not saved. To save the window layout the very simple solution is to open a new tab and close a new tab.

However this plugin seems to not take this approach of using tabnew/tabclose.

So I just added my own solution to my code. It is actually much simpler to roll out my own solution than trying to make this plugin or any other plugin fit my workflow.

Here is the commit for those interested.

shortcuts commented 1 day ago

Hey @ilan-schemoul thanks for using the plugin :D

I'm not totally sure to understand what is the issue here, I tried locally and disabling the plugin with killAllBuffersOnDisable properly kills every focused windows.

Looking at your issue description, it seems like you'd expect that enabling the plugin only keeps the focused window, right?

ilan-schemoul commented 1 day ago

Oh gosh I'm so stupid. killAllBuffersOnDisable obviously kills buffer when I disable. I expected it to kill other windows on enable. I do not know how I missed that, it's embarassing haha.

What I wanted is I have two windows window A | window B

When I NoNeckPain on Window A it first kills window B. Then center window A. When I disable NoNeckPain it stops center window A and then it shows again window A | window B

As I said I created my own solutions https://github.com/ilan-schemoul/nvim-config/commit/642ebf1f587ee003ed446b75b9bc8aaa935a638e when I use tabnew and tabclose without this plugin because it does what I want.