Skip to content

fix: prevent quit_on_open from opening file in the same window #1637

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

Merged
merged 6 commits into from
Oct 10, 2022

Conversation

Almo7aya
Copy link
Contributor

@Almo7aya Almo7aya commented Oct 9, 2022

fixes #1628

call view._prevent_buffer_override on BufWipeout instead of view.abandon_current_window when quit_on_open = true

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested OK: #1628 (comment)

@@ -373,7 +373,7 @@ local function setup_autocommands(opts)
if not opts.actions.open_file.quit_on_open then
create_nvim_tree_autocmd("BufWipeout", { pattern = "NvimTree_*", callback = view._prevent_buffer_override })
else
create_nvim_tree_autocmd("BufWipeout", { pattern = "NvimTree_*", callback = view.abandon_current_window })
create_nvim_tree_autocmd("BufWipeout", { pattern = "NvimTree_*", callback = view._prevent_buffer_override })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove if; both branches are the same

@alex-courtis
Copy link
Member

Also resolves an issue when loading a session with quit_on_open.

Error detected while processing BufWipeout Autocommands for "NvimTree_*":
Error executing lua callback: ...ck/packer/start/nvim-tree.lua.dev/lua/nvim-tree/view.lua:312: attempt to index a nil value
stack traceback:
        ...ck/packer/start/nvim-tree.lua.dev/lua/nvim-tree/view.lua:312: in function <...ck/packer/start/nvim-tree.lua.dev/lua/nvim-tree/view.lua:309>
        [C]: at 0x5648579a27f0
        [C]: in function 'pcall'
        ...ck/packer/start/nvim-tree.lua.dev/lua/nvim-tree/view.lua:81: in function 'wipe_rogue_buffer'
        ...ck/packer/start/nvim-tree.lua.dev/lua/nvim-tree/view.lua:87: in function 'create_buffer'
        ...ck/packer/start/nvim-tree.lua.dev/lua/nvim-tree/view.lua:216: in function 'open'
        ...ack/packer/start/nvim-tree.lua.dev/lua/nvim-tree/lib.lua:78: in function 'open_view_and_draw'
        ...ack/packer/start/nvim-tree.lua.dev/lua/nvim-tree/lib.lua:126: in function 'open'
        ...te/pack/packer/start/nvim-tree.lua.dev/lua/nvim-tree.lua:267: in function 'on_enter'
        ...te/pack/packer/start/nvim-tree.lua.dev/lua/nvim-tree.lua:755: in function <...te/pack/packer/start/nvim-tree.lua.dev/lua/nvim-tree.lua:754>

@Almo7aya
Copy link
Contributor Author

Almo7aya commented Oct 10, 2022

@alex-courtis I added a fix for opening a file using :e when the floating window is open, it was opening the file in a new vspilt, now it opens the file in a new buffer instead of a new window, what do u think?

@alex-courtis
Copy link
Member

@alex-courtis I added a fix for opening a file using :e when the floating window is open, it was opening the file in a new vspilt, now it opens the file in a new buffer instead of a new window, what do u think?

Let's just keep it consistent with non-floating: open in the previous (not picked) window.

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested OK:

  • defaults
  • quit_on_open
  • float
  • float quit_on_open

create_nvim_tree_autocmd("BufWipeout", {
pattern = "NvimTree_*",
callback = function()
if vim.bo.filetype == "NvimTree" then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@alex-courtis alex-courtis merged commit b01e7be into nvim-tree:master Oct 10, 2022
Almo7aya added a commit to Almo7aya/nvim-tree.lua that referenced this pull request Oct 11, 2022
…nvim-tree#1637)

* fix: prevent quit_on_open from opening in same window

* chore: remove condition for quit_on_open

* fix: prevent opening file in a new window on floting nvim-tree

* stylua

Co-authored-by: Alexander Courtis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File opens on the same nvim-tree window when quit_on_open = true
2 participants