Closed thisisrandy closed 1 year ago
Thanks for reporting this. (I didn't notice it because I use Vim and non-floating previews.)
Thanks also for the analysis. However b:source_window
is only needed when using non-floating preview windows.
I have fixed it in a7a83c3.
Well-observed. Thanks.
68f16eb
NVIM v0.9.0
The docs state:
I use all default options except for mappings and have
nvim_open_win
, sog:gitgutter_preview_win_floating
is1
by default (note that the wording reproduced above is misleading on this point). I have a mapping, reproduced at the bottom of this issue, that finds and focuses on the first floating window, and I use this for selective staging (feel free to direct your users to use something like it in a floating window-based workflow). I don't do selective staging super often, but it's always worked without issue until I tried it today. After writing the window, vim complains:If I turn
g:gitgutter_preview_win_floating
off and write the preview window instead, the issue does not occur.I did some digging, and it looks like the problem is in
s:open_hunk_preview_window
inautoload/gitgutter/hunk.vim
. The checksboth pass for me, so the function returns at line 475. However,
source_window
, which is set at the top of the function, isn't assigned tob:source_window
until further down at line 509. This is a relatively recent change (11d6e131), which explains why I've never encountered it before (as I said, I don't use this feature very often).I tried just doing away with
source_window
, which is only ever used once to assign its value tob:source_window
, and instead assigning directly tob:source_window
at the top of the function. This of course fails, because the variable is buffer-scoped and therefore not defined in the floating window. However, it works fine if we make it ~global~ a script variable, so I'm going to submit a PR with that change. Let me know what you think.My focus function for reference: