Hi Mike!

On Fr, 02 Sep 2016, Mike Williams wrote:

> Hi,
> 
> On 02/09/2016 12:22, Christian Brabandt wrote:
> >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.
> 
> It does fix my original problem but it has caused a new one.
> 
> With the same setup as above, delete all of pattern back to / and then
> hit return.  I get the expected "No previous regular expression" error.
> Then press return.  VIM should return back to the top of the file but
> instead displays the end of the file - until you move the cursor when it
> jumps back to the top of the file.  This does not happen without the
> patch applied.

good catch. updated patch attached. I added a test, but that didn't work 
as expected. Therefore the test is currently disabled. I verified 
manually, that either of <c-w> <c-u> <esc> <bs> <c-c> works as expected.

Best,
Christian
-- 
In der Politik errät sogar das Publikum stets das Listige und Feine;
nur das Große und Reine allein ist dazu gemacht, nicht geahnet zu
werden.
                -- Jean Paul

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
From a9553dd9ecbbbe7254250be28d7a05ee844e70c1 Mon Sep 17 00:00:00 2001
From: Christian Brabandt <c...@256bit.org>
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              | 27 ++++++++++++++++++++++++++-
 src/testdir/test_search.vim | 25 +++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/src/ex_getln.c b/src/ex_getln.c
index 110a95a..4fb4c73 100644
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -179,15 +179,20 @@ getcmdline(
 #ifdef FEAT_SEARCH_EXTRA
     pos_T	old_cursor;
     colnr_T	old_curswant;
+    colnr_T     init_curswant = curwin->w_curswant;
     colnr_T	old_leftcol;
+    colnr_T     init_leftcol = curwin->w_leftcol;
     linenr_T	old_topline;
+    linenr_T    init_topline = curwin->w_topline;
     pos_T       cursor_start;
     pos_T       match_start = curwin->w_cursor;
     pos_T       match_end;
 # ifdef FEAT_DIFF
     int		old_topfill;
+    int         init_topfill = curwin->w_topfill;
 # endif
     linenr_T	old_botline;
+    linenr_T	init_botline = curwin->w_botline;
     int		did_incsearch = FALSE;
     int		incsearch_postponed = FALSE;
 #endif
@@ -1006,13 +1011,33 @@ getcmdline(
 		    ccline.cmdbuff[ccline.cmdlen] = NUL;
 #ifdef FEAT_SEARCH_EXTRA
 		    if (ccline.cmdlen == 0)
+		    {
 			old_cursor = cursor_start;
+			/* save view settings, so that the screen
+			 * won't be restored at the wrong position */
+			old_curswant = init_curswant;
+			old_leftcol = init_leftcol;
+			old_topline = init_topline;
+# ifdef FEAT_DIFF
+			old_topfill = init_topfill;
+# endif
+			old_botline = init_botline;
+		    }
 		    else
 		    {
 			old_cursor = match_start;
 			decl(&old_cursor);
-		    }
+			/* save view settings, so that the screen
+			 * won't be restored at the wrong position */
+			old_curswant = curwin->w_curswant;
+			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();
 		}
 		else if (ccline.cmdlen == 0 && c != Ctrl_W
diff --git a/src/testdir/test_search.vim b/src/testdir/test_search.vim
index 6e51460..836beff 100644
--- a/src/testdir/test_search.vim
+++ b/src/testdir/test_search.vim
@@ -236,7 +236,32 @@ func Test_search_cmdline2()
   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())
+
+  " remove all history entries
+  for i in range(10)
+      call histdel('/')
+  endfor
+
+  " Test 3: reset the view,
+  " after deleting all characters from the search cmd
+  norm! 1gg0
+  " unfortunately, neither "/foo\<c-w>\<cr>", nor "/foo\<bs>\<bs>\<bs>\<cr>",
+  " nor "/foo\<c-u>\<cr>" works to delete the commandline.
+  " In that case Vim should return "E35 no previous regular expression",
+  " but it looks like Vim still sees /foo and therefore the test fails.
+  " Therefore, disableing this test
+  "call assert_fails(feedkeys("/foo\<c-w>\<cr>", 'tx'), 'E35')
+  "call assert_equal({'lnum': 1, 'leftcol': 0, 'col': 0, 'topfill': 0, 'topline': 1, 'coladd': 0, 'skipcol': 0, 'curswant': 0}, winsaveview())
+
   " clean up
+  set noincsearch
   call test_disable_char_avail(0)
   bw!
 endfunc
-- 
2.1.4

Raspunde prin e-mail lui