]> granicus.if.org Git - vim/commitdiff
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch' v8.0.1769
authorBram Moolenaar <Bram@vim.org>
Sat, 28 Apr 2018 11:56:09 +0000 (13:56 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 28 Apr 2018 11:56:09 +0000 (13:56 +0200)
Problem:    Repeated saving and restoring viewstate for 'incsearch'.
Solution:   Use a structure.

src/ex_getln.c
src/version.c

index ef8b4bdac683e0cb4b72ab238764be33b297e612..64914aa672e6f69c53c69e1d38e02931c67b1369 100644 (file)
@@ -187,6 +187,45 @@ empty_pattern(char_u *p)
 }
 #endif
 
+#ifdef FEAT_SEARCH_EXTRA
+typedef struct {
+    colnr_T    vs_curswant;
+    colnr_T    vs_leftcol;
+    linenr_T   vs_topline;
+# ifdef FEAT_DIFF
+    int                vs_topfill;
+# endif
+    linenr_T   vs_botline;
+    linenr_T   vs_empty_rows;
+} viewstate_T;
+
+    static void
+save_viewstate(viewstate_T *vs)
+{
+    vs->vs_curswant = curwin->w_curswant;
+    vs->vs_leftcol = curwin->w_leftcol;
+    vs->vs_topline = curwin->w_topline;
+# ifdef FEAT_DIFF
+    vs->vs_topfill = curwin->w_topfill;
+# endif
+    vs->vs_botline = curwin->w_botline;
+    vs->vs_empty_rows = curwin->w_empty_rows;
+}
+
+    static void
+restore_viewstate(viewstate_T *vs)
+{
+    curwin->w_curswant = vs->vs_curswant;
+    curwin->w_leftcol = vs->vs_leftcol;
+    curwin->w_topline = vs->vs_topline;
+# ifdef FEAT_DIFF
+    curwin->w_topfill = vs->vs_topfill;
+# endif
+    curwin->w_botline = vs->vs_botline;
+    curwin->w_empty_rows = vs->vs_empty_rows;
+}
+#endif
+
 /*
  * getcmdline() - accept a command line starting with firstc.
  *
@@ -225,21 +264,10 @@ getcmdline(
 #ifdef FEAT_SEARCH_EXTRA
     pos_T      search_start;           /* where 'incsearch' starts searching */
     pos_T       save_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;
+    viewstate_T        init_viewstate;
+    viewstate_T        old_viewstate;
     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, old_empty_rows;
-    linenr_T   init_botline = curwin->w_botline;
-    linenr_T   init_empty_rows = curwin->w_empty_rows;
     int                did_incsearch = FALSE;
     int                incsearch_postponed = FALSE;
 #endif
@@ -285,14 +313,8 @@ getcmdline(
     CLEAR_POS(&match_end);
     save_cursor = curwin->w_cursor;        /* may be restored later */
     search_start = curwin->w_cursor;
-    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;
-    old_empty_rows = curwin->w_empty_rows;
+    save_viewstate(&init_viewstate);
+    save_viewstate(&old_viewstate);
 #endif
 
     /*
@@ -1070,14 +1092,7 @@ getcmdline(
                        search_start = save_cursor;
                        /* 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;
-                       old_empty_rows = init_empty_rows;
+                       old_viewstate = init_viewstate;
                    }
 #endif
                    redrawcmd();
@@ -1800,14 +1815,7 @@ getcmdline(
                        update_topline();
                        validate_cursor();
                        highlight_match = TRUE;
-                       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;
-                       old_empty_rows = curwin->w_empty_rows;
+                       save_viewstate(&old_viewstate);
                        update_screen(NOT_VALID);
                        redrawcmdline();
                    }
@@ -2018,13 +2026,7 @@ cmdline_changed:
 
            /* first restore the old curwin values, so the screen is
             * positioned in the same way as the actual search command */
-           curwin->w_leftcol = old_leftcol;
-           curwin->w_topline = old_topline;
-# ifdef FEAT_DIFF
-           curwin->w_topfill = old_topfill;
-# endif
-           curwin->w_botline = old_botline;
-           curwin->w_empty_rows = old_empty_rows;
+           restore_viewstate(&old_viewstate);
            changed_cline_bef_curs();
            update_topline();
 
@@ -2112,14 +2114,7 @@ returncmd:
            }
            curwin->w_cursor = search_start;
        }
-       curwin->w_curswant = old_curswant;
-       curwin->w_leftcol = old_leftcol;
-       curwin->w_topline = old_topline;
-# ifdef FEAT_DIFF
-       curwin->w_topfill = old_topfill;
-# endif
-       curwin->w_botline = old_botline;
-       curwin->w_empty_rows = old_empty_rows;
+       restore_viewstate(&old_viewstate);
        highlight_match = FALSE;
        validate_cursor();      /* needed for TAB */
        redraw_all_later(SOME_VALID);
index 773e4b47795cef960037c9f7deefca598c9c1ed5..0a36b66af320f3cd5859598bfbeb5cd87a2404cf 100644 (file)
@@ -761,6 +761,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1769,
 /**/
     1768,
 /**/