On Mi, 31 Aug 2016, Mike Williams wrote:

> Hi,
> 
> I pretty much lurk here these days but remember seeing some
> discussion on changes to do with incremental search.  I am seeing
> strange screen jumps with incremental search with the current
> version 7.4.2295.  This is on on Windows and linux.
> 
> The following will reproduce the issue on Windows.  Start in the VIM
> source directory and invoke vim with gvim -u NONE -U NONE
> if_cscope.h. Next enable incsearch with ":set incsearch" and then
> start a search with "/Sto" - this should cause the display to jump
> to an enum near the end of the file.  At this point delete the o to
> leave "/St" as the search pattern and then hit return to finish the
> search.  I see VIM jumping back to the top of the file but with the
> cursor at the same position as for the search.  If then hit j to go
> down one line vim jumps back to the end of the file where the
> original search succeeded.
> 
> The action that seems to trigger the unexpected jumps around the
> buffer is deleting characters from the search pattern.  It can be
> confusing as the screen doesn't initially display what you are
> expecting (with the cursor appearing beyond the end of a line
> sometimes) and then any cursor movement cause the display to jump
> again.

Thanks for the almost perfect bug report (it just needed a patch to be 
perfect ;))

I could easily reproduce it. Turns out, that after backspacing, the view 
will not be reset correctly. So we have to save some variables there.

Please check the attached patch, which includes a test to fix this 
behaviour.

Best,
Christian
-- 
Wer weiß denn, ob das Leben nicht das Totsein ist und das Totsein
Leben
                -- Euripides (580-406 v. Chr.)

-- 
-- 
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/d/optout.
From 6e0de09303e580ef77c41bea61be91910eed1235 Mon Sep 17 00:00:00 2001
From: Christian Brabandt <[email protected]>
Date: Fri, 2 Sep 2016 13:09:37 +0200
Subject: [PATCH] Save and restore position after <bs> in search

patch 7.4.2259 introduced the possibility to jump to different matches
using <c-g>/<c-t> when 'incsearch' is set. This works by internally
setting the cursor position and saving and restoring the view for each
match.

Unfortunately, this introduced a regression, that when using <bs> to
delete some characters from the search prompt and pressing enter, the
view would be restored to the initial view (when we started the search
command), while the cursor might end up still on a different line (not
even being visible).

Therefore, let's just save the current view on deleteing characters from
the command line, so that it will be correctly restored on pressing
enter and add a test to verify, this actually works.
---
 src/ex_getln.c              | 8 ++++++++
 src/testdir/test_search.vim | 8 ++++++++
 2 files changed, 16 insertions(+)

diff --git a/src/ex_getln.c b/src/ex_getln.c
index 110a95a..369acb2 100644
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -1011,6 +1011,14 @@ getcmdline(
 		    {
 			old_cursor = match_start;
 			decl(&old_cursor);
+			/* save view settings, so that the screen
+			 * won't be restored at the wrong position */
+			old_leftcol = curwin->w_leftcol;
+			old_topline = curwin->w_topline;
+# ifdef FEAT_DIFF
+			old_topfill = curwin->w_topfill;
+# endif
+			old_botline = curwin->w_botline;
 		    }
 #endif
 		    redrawcmd();
diff --git a/src/testdir/test_search.vim b/src/testdir/test_search.vim
index 6e51460..0abb7fd 100644
--- a/src/testdir/test_search.vim
+++ b/src/testdir/test_search.vim
@@ -235,8 +235,16 @@ func Test_search_cmdline2()
   " go to previous match (on line 2)
   call feedkeys("/the\<C-G>\<C-G>\<C-G>\<C-T>\<C-T>\<C-T>\<cr>", 'tx')
   call assert_equal('  2 these', getline('.'))
+  " Test 2: keep the view,
+  " after deleting a character from the search cmd
+  call setline(1, ['  1', '  2 these', '  3 the', '  4 their', '  5 there', '  6 their', '  7 the', '  8 them', '  9 these', ' 10 foobar'])
+  resize 5
+  1
+  call feedkeys("/foo\<bs>\<cr>", 'tx')
+  call assert_equal({'lnum': 10, 'leftcol': 0, 'col': 4, 'topfill': 0, 'topline': 6, 'coladd': 0, 'skipcol': 0, 'curswant': 4}, winsaveview())
 
   " clean up
+  set noincsearch
   call test_disable_char_avail(0)
   bw!
 endfunc
-- 
2.1.4

Raspunde prin e-mail lui