Skip to content
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

[Feature] add an option to prevent auto-closing float terminal on leaving the window #420

Open
cjun714 opened this issue Mar 30, 2023 · 2 comments
Labels
difficulty: easy enhancement New feature or request help wanted Extra attention is needed

Comments

@cjun714
Copy link

cjun714 commented Mar 30, 2023

Current implementation is auto close term when switch from a float terminal.
I found the implementation is in toggleterm.lua:

local function handle_term_leave()
  local _, term = terms.identify()
  if not term then return end
  if config.persist_mode then term:persist_mode() end
  if term:is_float() then term:close() end
end

And there is no option or callback can be used to disable this behavior.

But sometimes auto-close float terminal is not the best choice.
For example, if I use a float terminal to compile or do some test job, if has error, I want to switch to code buffer to fix it without closing terminal since I need refer the output of terminal,
like below:

image

If I use terminal in the middle of the screen, auto close terminal for switching is reasonable.
But if I use float terminal on the top-right or bottom-right of the screen, auto-closing is not necessary, and in most user cases, it should be disabled.

Could you please considering to add an option flag to prevent this default behavior, so it can fit different strategy and requirement.

Thank you.

@akinsho
Copy link
Owner

akinsho commented Mar 30, 2023

@cjun714 it has never even occurred to me that a person would position the float in the top right like you are doing in your screenshot so at first this issue seemed not to make sense since I assume that most people use it centered like I do.

Please feel free to raise a PR to add this, I'm definitely fine for this to be supported on a global and per terminal case but this must not change the defaults.

Since the use case is niche enough I won't implement this myself but it should be easy enough for you to do it. You just need to:

  • Add a new option to the Terminal:new function similar to all the other ones.
  • Update the documentation and the type annotations
  • Actually check the option before auto closing

@akinsho akinsho changed the title [Feature] Please consider to add an option to prevent auto-closing float terminal when switching [Feature] add an option to prevent auto-closing float terminal on leaving the window Mar 30, 2023
@akinsho akinsho added enhancement New feature or request help wanted Extra attention is needed difficulty: easy labels Mar 30, 2023
@cjun714
Copy link
Author

cjun714 commented Mar 30, 2023

I use vim-floaterm before, and this feature is well supported.
But I found your plugin provide some good features like sendline to terminal, so I try to move to this new plugin.

I modify the code, but I find also need to modify ToggleTerm ,
since vim-floaterm's implementation can handle if a float window is displayed but not be focused, in this case ToggleTerm will not toggle terminal, but just switch focus to that float window.

So I think need further design and modification.
Thanks for your quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: easy enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants