willothy / flatten.nvim

Open files and command output from wezterm, kitty, and neovim terminals in your current neovim instance

Home Page:https://luarocks.org/modules/willothy/flatten.nvim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

post_open shall provide bufnr and winnr for newly opened file

ragu-manjegowda opened this issue · comments

Describe the bug
If we want to do something in the call back that moves the focus to different tab, it is not possible to shift the focus back to newly opened tab.

To Reproduce
Steps to reproduce the behavior:

config

-- Setup toggle terminal

local ftzsh = fterm:new({
    ft = 'fterm_zsh',
    cmd = "zsh",
    dimensions = {
        height = 0.9,
        width = 0.9
    }
})

function M.__fterm_zsh()
    ftzsh:toggle()
end

-- Hide the terminal before jumping to new tab so that it opens in current tab next time.

{
    callbacks = {
        post_open = function(_, winnr, _, _)
            require("fterm").__fterm_zsh()  <-------- this moves the focus to current window where floating terminal is currently open
            vim.api.nvim_set_current_win(winnr)    <---------- need winnr of newly opened file here
        end
    },
    window = {
        open = "tab"
    }
}

With toggle terminal (fterm)

Open a file

Expected behavior
Focus should be on newly opened file

Screenshots
n/a

Desktop (please complete the following information):

  • Linux (Arch, Ubuntu)
  • 0.9

Additional context
It helps users to provide both current and new win/buf numbers to customize based on the use case. Let me know if you need more information or context.

Thanks for reporting, I'll look into this soon!

Sorry for taking so long on this - to be clear, you want the window number of the terminal to be passed as well? I'm a bit unclear on the use case here as I don't really use tabs.

you want the window number of the terminal to be passed as well

If you can provide that why not? However, what I was looking for is window number of the newly opened file.

Lets say I have a tab with file A currently focused and I try to open file B in new tab from floating terminal, in post_open hook I would like to see the window number of the tab with file B.

It turns out this was what we were supposed to be doing the whole time, and this was definitely a bug. That's why I was initially confused. Will be fixed shortly.