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

Fix focus top left window bug #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wolever
Copy link

@wolever wolever commented Jun 1, 2017

With newer versions of Vim, the top left window will be focused after
opening the fuf menu. This patch restores the window focus after the
menu is closed.

Nb: hasn't been tested on older versions of Vim.

With newer versions of Vim, the top left window will be focused after
opening the fuf menu. This patch restores the window focus after the
menu is closed.
@ernstki
Copy link

ernstki commented Oct 10, 2017

@wolever Thank you very much, kind traveler.

Not obvious from your PR description, but it also appears to fix the very annoying behavior of opening the result of, for example, a :FufBuffer selection in a split other than the current one (unless of course, the current split is topmost and left-most), a circumstance that had almost caused me to give up on FuzzyFinder forever.

Since it seems not very likely this will ever be merged in (unless FuzzyFinder gets a new maintainer), here's how to generate a patch file from this PR and apply it to an existing installation of FuzzyFinder.

# I use Pathogen, so your installation path might be different
cd ~/.vim/bundle/FuzzyFinder
curl -Lo fix-top-left-focus-bug.patch https://github.com/vim-scripts/FuzzyFinder/pull/2.diff
patch -p1 <fix-top-left-focus-bug.patch

ernstki added a commit to ernstki/FuzzyFinder that referenced this pull request Oct 27, 2017
@bemurphy
Copy link

bemurphy commented Apr 7, 2018

@wolever you just saved me so much headache, this is amazing. Thank you!

@wolever
Copy link
Author

wolever commented Aug 21, 2021

Thank you again, @ernstki! I just moved to a new machine, had the same bug, and used your same solution :)

For any future folk who find this, here's the content of the diff, just in case something happens to it:

diff --git a/autoload/fuf.vim b/autoload/fuf.vim
index fe9e6eb..78be490 100644
--- a/autoload/fuf.vim
+++ b/autoload/fuf.vim
@@ -706,6 +706,11 @@ let s:FUF_BUF_NAME = '[fuf]'
 
 "
 function s:activateFufBuffer()
+  " Save the last window number so we can switch back to it later (otherwise,
+  " at least with more recent versions of Vim, we end up with the top left
+  " window focused)
+  let s:fuf_buffer_last_winnr = winnr()
+
   " lcd . : To avoid the strange behavior that unnamed buffer changes its cwd
   "         if 'autochdir' was set on.
   lcd .
@@ -733,6 +738,7 @@ function s:deactivateFufBuffer()
     AutoComplPopUnlock
   endif
   call l9#tempbuffer#close(s:FUF_BUF_NAME)
+  exec s:fuf_buffer_last_winnr . "wincmd w"
 endfunction
 
 " }}}1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants