Skip to content

Conversation

mmrwoods
Copy link

@mmrwoods mmrwoods commented May 27, 2025

This adds optional support for using Vim popup windows, which must be
enabled by setting g:git_messenger_vimpopup_enabled to v:true, and works
similar to Neovim with g:git_messenger_always_into_popup set to v:true

It does require quite a bit of conditional code as you cannot enter a
Vim popup, unlike a Neovim float or the preview window, but it works!

Has been tested, manually, with Vim 8.1.2384 (first version of Vim to
include support for +popupwin) and with Vim 9.1.950, both work fine.

There are some limitations as you can't enter the popup, for example key
mappings are specified in a filter function, not as buffer local maps,
and there are likely to be some bugs as this is new, but generally it
works as you probably expect, the popup opens in the same position as
the Neovim floating window, the git-messenger mappings work, running the
:GitMessenger command opens and closes the popup, mouse scrolling works,
and some keys like CTRL-U, CTRL-D are mapped for scrolling up and down.

@mmrwoods mmrwoods force-pushed the vim-popupwin branch 4 times, most recently from b7fdb69 to 47da31c Compare May 29, 2025 14:56
@mmrwoods mmrwoods changed the title Experimental support for Vim 8.1+ popup windows Add support for Vim 8.1+ popup windows May 29, 2025
This adds optional support for using Vim popup windows, which must be
enabled by setting g:git_messenger_vimpopup_enabled to v:true, and works
similar to Neovim with g:git_messenger_always_into_popup set to v:true

It does require quite a bit of conditional code as you cannot enter a
Vim popup, unlike a Neovim float or the preview window, but it works!

Has been tested, manually, with Vim 8.1.2384 (first version of Vim to
include support for +popupwin) and with Vim 9.1.950, both work fine.

There are some limitations as you can't enter the popup, for example key
mappings are specified in a filter function, not as buffer local maps,
and there are likely to be some bugs as this is new, but generally it
works as you probably expect, the popup opens in the same position as
the Neovim floating window, the git-messenger mappings work, running the
:GitMessenger command opens and closes the popup, mouse scrolling works,
and some keys like CTRL-U, CTRL-D are mapped for scrolling up and down.
mmrwoods added 5 commits May 30, 2025 09:32
These are required for the popup to function correctly, so make it an
error to try and override them via g:git_messenger_vimpopup_win_opts
When g:git_messenger_close_on_cursor_moved is set to v:false,
plugin-git-messenger-close autocmd won't exist, so use :silent!
This updates the behaviour when Vim popup is enabled to work more like
Neovim floating windows or the preview window. Entering a vim popup is
emulated by initially disabling popup keymaps, and only enabling them
once the popup is marked as "entered", which means the default behaviour
is now almost identical for Vim popup, Neovim float and preview window.

Running :GitMessenger opens the Vim popup, running it again enables the
keymaps so you can navigate within the popup, running it again closes
the popup, and g:git_messenger_always_into_popup is also respected.
Needed to ensure the popup is not only closed, but opener buffer local
variable storing a reference to the popup object/dict also removed.
Without this switching windows or buffers while the popup is open leaves
the buffer local var behind and breaks future calls to :GitMessenger
As you can't enter a Vim popup window, you can't easily yank the current
commit hash, and that seems a natural thing to want to do (I certainly
found myself wanting to do it soon after starting to use git-messenger).

To address this, map 'c' to yank the current commit hash to v:register
(kind of, while the code behaves the same as using v:register, it
doesn't actually use v:register due to some clash with vim-cutlass).

While this is added primarily to aid Vim popup users, it doesn't break
anything for Neovim floating win or preview window users as the buffer
is not modifiable, and it seems a handy mapping for all users anyway.
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.

1 participant