Skip to content

Commit 620b710

Browse files
committed
Emulate entering vim popup, more like Neovim float
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.
1 parent 051465e commit 620b710

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ Setting `v:false` to this variable removes all the margins.
265265

266266
When this value is set to `v:true`, enables the use of popup windows in Vim. This feature is
267267
experimental, and has some limitations as it is not possible to enter a popup window in Vim (unlike
268-
floating windows in Neovim). Similar to using Neovim with `g:git_messenger_always_into_popup` set to `v:true`.
268+
floating windows in Neovim). Entering a popup is emulated by initially disabling keyboard mappings
269+
for the popup window, and only enabling them when it been marked as "entered", either by running the
270+
`:GitMessenger` command a second time, or with `g:git_messenger_always_into_popup` set to `v:true`.
269271

270272
#### `g:git_messenger_vimpopup_win_opts` (Default `{}`)
271273

autoload/gitmessenger/popup.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ let s:popup.scroll = funcref('s:popup__scroll')
6868

6969
function! s:popup__into() dict abort
7070
if self.type ==# 'popup'
71+
let self.entered = v:true
7172
return
7273
endif
7374
let winnr = self.get_winnr()
@@ -174,6 +175,10 @@ endfunction
174175
let s:popup.vimpopup_keymaps = funcref('s:popup__vimpopup_keymaps')
175176

176177
function! s:popup__vimpopup_win_filter(win_id, key) dict abort
178+
" if popup not marked as entered, do not handle any keys
179+
if !self.entered
180+
return 0
181+
endif
177182
" Note: default q handler assumes we are in the popup window, but in Vim we
178183
" cannot enter the popup window, so we override the handling here for now
179184
let keymaps = self.vimpopup_keymaps()
@@ -286,6 +291,11 @@ function! s:popup__open() dict abort
286291
" Note: setbufvar() seems necessary to trigger Filetype autocmds
287292
call setbufvar(winbufnr(win_id), '&filetype', self.opts.filetype)
288293
endif
294+
if has_key(self.opts, 'enter') && self.opts.enter
295+
let self.entered = v:true
296+
else
297+
let self.entered = v:false
298+
endif
289299
" Allow multiple invocations of :GitMessenger command to toggle popup
290300
" See gitmessenger#popup#close_current_popup() and gitmessenger#new()
291301
let b:__gitmessenger_popup = self " local to opener, removed by callback
@@ -493,6 +503,9 @@ function! gitmessenger#popup#close_current_popup() abort
493503
if !exists('b:__gitmessenger_popup')
494504
return 0
495505
endif
506+
if b:__gitmessenger_popup.type ==# 'popup' && !b:__gitmessenger_popup.entered
507+
return 0
508+
endif
496509
call b:__gitmessenger_popup.close()
497510
" TODO?: Back to opened_at pos by setpos()
498511
return 1

doc/git-messenger.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,11 @@ might be useful when you enable borders of popup window with
301301

302302
When this value is set to |v:true|, enables the use of popup windows in Vim.
303303
This feature is experimental, and has some limitations as it is not possible
304-
to enter a popup window in Vim (unlike floating windows in Neovim). Similar
305-
to using Neovim with |g:git_messenger_always_into_popup| set to |v:true|.
304+
to enter a popup window in Vim (unlike floating windows in Neovim). Entering a
305+
popup is emulated by initially disabling keyboard mappings for the popup
306+
window, and only enabling them when it been marked as "entered", either by
307+
running the |:GitMessenger| command a second time, or with
308+
|g:git_messenger_always_into_popup| set to |v:true|.
306309

307310
*g:git_messenger_vimpopup_win_opts* (Default |{}|)
308311

0 commit comments

Comments
 (0)