Navigation Menu

Skip to content

Commit

Permalink
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Browse files Browse the repository at this point in the history
Problem:    Repeated saving and restoring viewstate for 'incsearch'.
Solution:   Use a structure.
  • Loading branch information
brammool committed Apr 28, 2018
1 parent 451fc7b commit 9b25af3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 52 deletions.
99 changes: 47 additions & 52 deletions src/ex_getln.c
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

/*
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -2018,13 +2026,7 @@ getcmdline(

/* 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();

Expand Down Expand Up @@ -2112,14 +2114,7 @@ getcmdline(
}
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);
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -761,6 +761,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1769,
/**/
1768,
/**/
Expand Down

0 comments on commit 9b25af3

Please sign in to comment.