mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.0.1769: refactor save/restore of viewstate #11701
Problem: Repeated saving and restoring viewstate for 'incsearch'.
Solution: Use a structure.
9b25af3620
This commit is contained in:
parent
a4d21f0592
commit
462ee281b7
@ -136,6 +136,15 @@ struct cmdline_info {
|
|||||||
/// Last value of prompt_id, incremented when doing new prompt
|
/// Last value of prompt_id, incremented when doing new prompt
|
||||||
static unsigned last_prompt_id = 0;
|
static unsigned last_prompt_id = 0;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
colnr_T vs_curswant;
|
||||||
|
colnr_T vs_leftcol;
|
||||||
|
linenr_T vs_topline;
|
||||||
|
int vs_topfill;
|
||||||
|
linenr_T vs_botline;
|
||||||
|
int vs_empty_rows;
|
||||||
|
} viewstate_T;
|
||||||
|
|
||||||
typedef struct command_line_state {
|
typedef struct command_line_state {
|
||||||
VimState state;
|
VimState state;
|
||||||
int firstc;
|
int firstc;
|
||||||
@ -151,18 +160,8 @@ typedef struct command_line_state {
|
|||||||
int histype; // history type to be used
|
int histype; // history type to be used
|
||||||
pos_T search_start; // where 'incsearch' starts searching
|
pos_T search_start; // where 'incsearch' starts searching
|
||||||
pos_T save_cursor;
|
pos_T save_cursor;
|
||||||
colnr_T old_curswant;
|
viewstate_T init_viewstate;
|
||||||
colnr_T init_curswant;
|
viewstate_T old_viewstate;
|
||||||
colnr_T old_leftcol;
|
|
||||||
colnr_T init_leftcol;
|
|
||||||
linenr_T old_topline;
|
|
||||||
linenr_T init_topline;
|
|
||||||
int old_topfill;
|
|
||||||
int init_topfill;
|
|
||||||
linenr_T old_botline;
|
|
||||||
linenr_T init_botline;
|
|
||||||
int old_empty_rows;
|
|
||||||
int init_empty_rows;
|
|
||||||
pos_T match_start;
|
pos_T match_start;
|
||||||
pos_T match_end;
|
pos_T match_end;
|
||||||
int did_incsearch;
|
int did_incsearch;
|
||||||
@ -230,6 +229,28 @@ static int compl_selected;
|
|||||||
|
|
||||||
static int cmd_hkmap = 0; // Hebrew mapping during command line
|
static int cmd_hkmap = 0; // Hebrew mapping during command line
|
||||||
|
|
||||||
|
static void save_viewstate(viewstate_T *vs)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
{
|
||||||
|
vs->vs_curswant = curwin->w_curswant;
|
||||||
|
vs->vs_leftcol = curwin->w_leftcol;
|
||||||
|
vs->vs_topline = curwin->w_topline;
|
||||||
|
vs->vs_topfill = curwin->w_topfill;
|
||||||
|
vs->vs_botline = curwin->w_botline;
|
||||||
|
vs->vs_empty_rows = curwin->w_empty_rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void restore_viewstate(viewstate_T *vs)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
{
|
||||||
|
curwin->w_curswant = vs->vs_curswant;
|
||||||
|
curwin->w_leftcol = vs->vs_leftcol;
|
||||||
|
curwin->w_topline = vs->vs_topline;
|
||||||
|
curwin->w_topfill = vs->vs_topfill;
|
||||||
|
curwin->w_botline = vs->vs_botline;
|
||||||
|
curwin->w_empty_rows = vs->vs_empty_rows;
|
||||||
|
}
|
||||||
|
|
||||||
/// Internal entry point for cmdline mode.
|
/// Internal entry point for cmdline mode.
|
||||||
///
|
///
|
||||||
/// caller must use save_cmdline and restore_cmdline. Best is to use
|
/// caller must use save_cmdline and restore_cmdline. Best is to use
|
||||||
@ -240,22 +261,18 @@ static uint8_t *command_line_enter(int firstc, long count, int indent)
|
|||||||
static int cmdline_level = 0;
|
static int cmdline_level = 0;
|
||||||
cmdline_level++;
|
cmdline_level++;
|
||||||
|
|
||||||
CommandLineState state, *s = &state;
|
CommandLineState state = {
|
||||||
memset(s, 0, sizeof(CommandLineState));
|
.firstc = firstc,
|
||||||
s->firstc = firstc;
|
.count = count,
|
||||||
s->count = count;
|
.indent = indent,
|
||||||
s->indent = indent;
|
.save_msg_scroll = msg_scroll,
|
||||||
s->save_msg_scroll = msg_scroll;
|
.save_State = State,
|
||||||
s->save_State = State;
|
.ignore_drag_release = true,
|
||||||
|
.match_start = curwin->w_cursor,
|
||||||
|
};
|
||||||
|
CommandLineState *s = &state;
|
||||||
s->save_p_icm = vim_strsave(p_icm);
|
s->save_p_icm = vim_strsave(p_icm);
|
||||||
s->ignore_drag_release = true;
|
save_viewstate(&state.init_viewstate);
|
||||||
s->match_start = curwin->w_cursor;
|
|
||||||
s->init_curswant = curwin->w_curswant;
|
|
||||||
s->init_leftcol = curwin->w_leftcol;
|
|
||||||
s->init_topline = curwin->w_topline;
|
|
||||||
s->init_topfill = curwin->w_topfill;
|
|
||||||
s->init_botline = curwin->w_botline;
|
|
||||||
s->init_empty_rows = curwin->w_empty_rows;
|
|
||||||
|
|
||||||
if (s->firstc == -1) {
|
if (s->firstc == -1) {
|
||||||
s->firstc = NUL;
|
s->firstc = NUL;
|
||||||
@ -273,12 +290,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent)
|
|||||||
clearpos(&s->match_end);
|
clearpos(&s->match_end);
|
||||||
s->save_cursor = curwin->w_cursor; // may be restored later
|
s->save_cursor = curwin->w_cursor; // may be restored later
|
||||||
s->search_start = curwin->w_cursor;
|
s->search_start = curwin->w_cursor;
|
||||||
s->old_curswant = curwin->w_curswant;
|
save_viewstate(&state.old_viewstate);
|
||||||
s->old_leftcol = curwin->w_leftcol;
|
|
||||||
s->old_topline = curwin->w_topline;
|
|
||||||
s->old_topfill = curwin->w_topfill;
|
|
||||||
s->old_botline = curwin->w_botline;
|
|
||||||
s->old_empty_rows = curwin->w_empty_rows;
|
|
||||||
|
|
||||||
assert(indent >= 0);
|
assert(indent >= 0);
|
||||||
|
|
||||||
@ -448,12 +460,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent)
|
|||||||
}
|
}
|
||||||
curwin->w_cursor = s->search_start; // -V519
|
curwin->w_cursor = s->search_start; // -V519
|
||||||
}
|
}
|
||||||
curwin->w_curswant = s->old_curswant;
|
restore_viewstate(&s->old_viewstate);
|
||||||
curwin->w_leftcol = s->old_leftcol;
|
|
||||||
curwin->w_topline = s->old_topline;
|
|
||||||
curwin->w_topfill = s->old_topfill;
|
|
||||||
curwin->w_botline = s->old_botline;
|
|
||||||
curwin->w_empty_rows = s->old_empty_rows;
|
|
||||||
highlight_match = false;
|
highlight_match = false;
|
||||||
validate_cursor(); // needed for TAB
|
validate_cursor(); // needed for TAB
|
||||||
redraw_all_later(SOME_VALID);
|
redraw_all_later(SOME_VALID);
|
||||||
@ -1118,12 +1125,7 @@ static void command_line_next_incsearch(CommandLineState *s, bool next_match)
|
|||||||
update_topline();
|
update_topline();
|
||||||
validate_cursor();
|
validate_cursor();
|
||||||
highlight_match = true;
|
highlight_match = true;
|
||||||
s->old_curswant = curwin->w_curswant;
|
save_viewstate(&s->old_viewstate);
|
||||||
s->old_leftcol = curwin->w_leftcol;
|
|
||||||
s->old_topline = curwin->w_topline;
|
|
||||||
s->old_topfill = curwin->w_topfill;
|
|
||||||
s->old_botline = curwin->w_botline;
|
|
||||||
s->old_empty_rows = curwin->w_empty_rows;
|
|
||||||
update_screen(NOT_VALID);
|
update_screen(NOT_VALID);
|
||||||
redrawcmdline();
|
redrawcmdline();
|
||||||
} else {
|
} else {
|
||||||
@ -1244,12 +1246,7 @@ static int command_line_handle_key(CommandLineState *s)
|
|||||||
s->search_start = s->save_cursor;
|
s->search_start = s->save_cursor;
|
||||||
// save view settings, so that the screen won't be restored at the
|
// save view settings, so that the screen won't be restored at the
|
||||||
// wrong position
|
// wrong position
|
||||||
s->old_curswant = s->init_curswant;
|
s->old_viewstate = s->init_viewstate;
|
||||||
s->old_leftcol = s->init_leftcol;
|
|
||||||
s->old_topline = s->init_topline;
|
|
||||||
s->old_topfill = s->init_topfill;
|
|
||||||
s->old_botline = s->init_botline;
|
|
||||||
s->old_empty_rows = s->init_empty_rows;
|
|
||||||
}
|
}
|
||||||
redrawcmd();
|
redrawcmd();
|
||||||
} else if (ccline.cmdlen == 0 && s->c != Ctrl_W
|
} else if (ccline.cmdlen == 0 && s->c != Ctrl_W
|
||||||
@ -1879,11 +1876,7 @@ static int command_line_changed(CommandLineState *s)
|
|||||||
|
|
||||||
// first restore the old curwin values, so the screen is
|
// first restore the old curwin values, so the screen is
|
||||||
// positioned in the same way as the actual search command
|
// positioned in the same way as the actual search command
|
||||||
curwin->w_leftcol = s->old_leftcol;
|
restore_viewstate(&s->old_viewstate);
|
||||||
curwin->w_topline = s->old_topline;
|
|
||||||
curwin->w_topfill = s->old_topfill;
|
|
||||||
curwin->w_botline = s->old_botline;
|
|
||||||
curwin->w_empty_rows = s->old_empty_rows;
|
|
||||||
changed_cline_bef_curs();
|
changed_cline_bef_curs();
|
||||||
update_topline();
|
update_topline();
|
||||||
|
|
||||||
@ -1944,11 +1937,7 @@ static int command_line_changed(CommandLineState *s)
|
|||||||
|
|
||||||
// Restore the window "view".
|
// Restore the window "view".
|
||||||
curwin->w_cursor = s->save_cursor;
|
curwin->w_cursor = s->save_cursor;
|
||||||
curwin->w_curswant = s->old_curswant;
|
restore_viewstate(&s->old_viewstate);
|
||||||
curwin->w_leftcol = s->old_leftcol;
|
|
||||||
curwin->w_topline = s->old_topline;
|
|
||||||
curwin->w_topfill = s->old_topfill;
|
|
||||||
curwin->w_botline = s->old_botline;
|
|
||||||
update_topline();
|
update_topline();
|
||||||
|
|
||||||
redrawcmdline();
|
redrawcmdline();
|
||||||
|
Loading…
Reference in New Issue
Block a user