chrisbra / Recover.vim

A Plugin to show a diff, whenever recovering a buffer
http://www.vim.org/scripts/script.php?script_id=3068
247 stars 25 forks source link

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

Closed lyokha closed 12 years ago

lyokha commented 12 years ago

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 commented 12 years ago

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 commented 12 years ago

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