I discovered a problem with the 'scrollbind' setting which causes one of
the bound windows to scroll unexpectedly introducing an offset to the
bounding thus effectively destroying the desired setup.
The attached script scb-problem.vim when sourced will make the problem
apparent. The intention is for the line "line X" on the left to be
aligned with line "LINE Y" on the right. The actual situation is that
after the script runs I get an offset of 523 lines between the windows.
The attached patch fixes it and provides a test.
But NOTE!
In its current shape the test is pretty much useless: it doesn't
reproduce the problem even before applying the patch. Sorry, but try as
I may, I can't transform scb-problem.vim into a useful test for Vim.
Perhaps someone more knowledgeable will be able to change a line or two
to make it work. If it happens so, I would be extremely grateful if
someone would explain to me what is wrong with my approach.
--
Cheers,
Lech
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
set lines=50
set scrolloff=0
wincmd n
wincmd o
setl bt=nofile
for i in range(1, 1000)
call setline(i, 'LINE ' . i)
endfor
500
normal zt
normal M
aboveleft vert new
setl bt=nofile
%del _
for i in range(1, 1000)
call setline(i, 'line ' . i)
endfor
500
normal zt
normal M
setl scb
wincmd p
function! ReproduceProblem()
setl scb
endfunction
call feedkeys(":call ReproduceProblem()\n\<C-w>\<C-w>", 't')
" For some reason to reproduce the problem it is necessary to make the
" function call.
" The windows should be scrollbound with their tops showing the same line
" numbers (i.e. there should be no offset in the binding) but there is an
" offset of 523 lines.
diff --git a/src/option.c b/src/option.c
index 0932bb8..a1f536c 100644
--- a/src/option.c
+++ b/src/option.c
@@ -7801,7 +7801,10 @@ set_bool_option(opt_idx, varp, value, opt_flags)
else if ((int *)varp == &curwin->w_p_scb)
{
if (curwin->w_p_scb)
+ {
do_check_scrollbind(FALSE);
+ curwin->w_scbind_pos = curwin->w_topline;
+ }
}
#endif
diff --git a/src/testdir/Makefile b/src/testdir/Makefile
index 6573e8a..85b7c4d 100644
--- a/src/testdir/Makefile
+++ b/src/testdir/Makefile
@@ -29,7 +29,7 @@ SCRIPTS = test1.out test2.out test3.out test4.out test5.out test6.out \
test79.out test80.out test81.out test82.out test83.out \
test84.out test85.out test86.out test87.out test88.out \
test89.out test90.out test91.out test92.out test93.out \
- test94.out test95.out
+ test94.out test95.out test96.out
SCRIPTS_GUI = test16.out
diff --git a/src/testdir/test96.in b/src/testdir/test96.in
new file mode 100644
index 0000000..11c9ff1
--- /dev/null
+++ b/src/testdir/test96.in
@@ -0,0 +1,41 @@
+Test for 'scrollbind' causing an unexpected scroll of one of the windows.
+STARTTEST
+:set lines=21
+:let end = 10 * &lines
+:let mid = end / 2
+:enew
+:" Let's fill the window with "Line 1", "Line 2", "Line 3", etc.
+:for i in range(1, end) | call setline(i, 'Line ' . i) | endfor
+:exe mid
+:normal zt
+:normal M
+:" Let's create another window and fill it with "XXXXX 1", "XXXXX 2", "XXXXX 3", etc.
+:aboveleft vert new
+:for i in range(1, end) | call setline(i, 'XXXXX ' . i) | endfor
+:exe mid
+:normal zt
+:normal M
+:" Now let's scrollbind the windows
+:setl scrollbind
+:wincmd p
+:setl scrollbind
+:" At this point the unexpected scroll used to happen
+:wincmd p
+:let topLineLeft = line('w0')
+:wincmd p
+:let topLineRight = line('w0')
+:setl noscrollbind
+:wincmd p
+:setl noscrollbind
+:q!
+:%del _
+:call setline(1, 'Top line of the left window: ' . string(topLineLeft))
+:call setline(2, 'Top line of the right window: ' . string(topLineRight))
+:w! test.out
+:brewind
+ENDTEST
+
+STARTTEST
+:qa!
+ENDTEST
+
diff --git a/src/testdir/test96.ok b/src/testdir/test96.ok
new file mode 100644
index 0000000..408f3de
--- /dev/null
+++ b/src/testdir/test96.ok
@@ -0,0 +1,2 @@
+Top line of the left window: 105
+Top line of the right window: 105