Cursor positioned in wrong window when one or more windows were autoopen #6

Closed
lyokha opened this Issue Jun 17, 2012 · 2 comments

Projects

None yet

2 participants

@lyokha
lyokha commented Jun 17, 2012

I found that 'wincmd l' workaround must not be triggered when there are windows to autoopen (e.g. tagbar or NERDtree etc.). Simple fix is to additionally check if number of open windows is less than 3 (i.e. there are only 2 windows to diff). Here is a very simple patch against current repo version:

--- autoload/recover.vim    2012-04-20 04:42:54.000000000 +0400
+++ autoload/recover.vim.new    2012-06-17 17:41:51.320910297 +0400
@@ -76,9 +76,10 @@
        " Not sure, why this needs feedkeys
        " Sometimes cursor is wrong, I hate when this happens
        " Cursor is wrong only when there is a single buffer open, a simple
-       " workaround for that is to check if bufnr('') is 1: in this case
-       " ':wincmd l\n:0\n' must be fed
-       if bufnr('') == 1
+       " workaround for that is to check if bufnr('') is 1 and total number
+       " of windows in current tab is less than 3 (i.e. no windows were
+       " autoopen): in this case " ':wincmd l\n:0\n' must be fed
+       if bufnr('') == 1 && winnr('$') < 3
        call feedkeys(":wincmd l\n", 't')
        endif
        call feedkeys(":0\n", 't')

I tested this in different conditions (with and without autoopen windows, in current window / in new tagbar etc.): it seems to work fine.

Cheers, Alexey.

@lyokha
lyokha commented Jun 17, 2012

Sorry, a typo in comment, diff must be:

--- autoload/recover.vim    2012-04-20 04:42:54.000000000 +0400
+++ autoload/recover.vim.new    2012-06-17 18:03:56.577048852 +0400
@@ -76,9 +76,10 @@
        " Not sure, why this needs feedkeys
        " Sometimes cursor is wrong, I hate when this happens
        " Cursor is wrong only when there is a single buffer open, a simple
-       " workaround for that is to check if bufnr('') is 1: in this case
-       " ':wincmd l\n:0\n' must be fed
-       if bufnr('') == 1
+       " workaround for that is to check if bufnr('') is 1 and total number
+       " of windows in current tab is less than 3 (i.e. no windows were
+       " autoopen): in this case ':wincmd l\n:0\n' must be fed
+       if bufnr('') == 1 && winnr('$') < 3
        call feedkeys(":wincmd l\n", 't')
        endif
        call feedkeys(":0\n", 't')
@chrisbra
Owner

Hi lyokha!

On So, 17 Jun 2012, lyokha wrote:

I found that 'wincmd l' workaround must not be triggered when there are windows to autoopen (e.g. tagbar or NERDtree etc.). Simple fix is to additionally check if number of open windows is less than 3 (i.e. there are only 2 windows to diff). Here is a very simple patch against current repo version:

--- autoload/recover.vim  2012-04-20 04:42:54.000000000 +0400
+++ autoload/recover.vim.new  2012-06-17 17:41:51.320910297 +0400
@@ -76,9 +76,10 @@
      " Not sure, why this needs feedkeys
      " Sometimes cursor is wrong, I hate when this happens
      " Cursor is wrong only when there is a single buffer open, a simple
-     " workaround for that is to check if bufnr('') is 1: in this case
-     " ':wincmd l\n:0\n' must be fed
-     if bufnr('') == 1
+     " workaround for that is to check if bufnr('') is 1 and total number
+     " of windows in current tab is less than 3 (i.e. no windows were
+     " autoopen): in this case " ':wincmd l\n:0\n' must be fed
+     if bufnr('') == 1 && winnr('$') < 3
      call feedkeys(":wincmd l\n", 't')
      endif
      call feedkeys(":0\n", 't')

I tested this in different conditions (with and without autoopen windows, in current window / in new tagbar etc.): it seems to work fine.

Thanks for the patch. Looks good and I included it.

regards,

Christian

Aufrichtigkeit ist eine Tugend, welche ihren Lohn schon im Namen mit
sich führt: Sie richtet auf.
-- Jules Ferry

@chrisbra chrisbra closed this Aug 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment