Skip to content

Commit

Permalink
Fix search history scrolling when --incsearch is set.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Oct 12, 2021
1 parent 1974e5f commit 440f178
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmdbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static int prompt_col; /* Column of cursor just after prompt */
static char *cp; /* Pointer into cmdbuf */
static int cmd_offset; /* Index into cmdbuf of first displayed char */
static int literal; /* Next input char should not be interpreted */
static int updown_match = -1; /* Prefix length in up/down movement */
public int updown_match = -1; /* Prefix length in up/down movement */

#if TAB_COMPLETE_FILENAME
static int cmd_complete LESSPARAMS((int action));
Expand Down
18 changes: 16 additions & 2 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ extern void *ml_search;
extern void *ml_examine;
extern int wheel_lines;
extern int header_lines;
extern int updown_match;
#if SHELL_ESCAPE || PIPEC
extern void *ml_shell;
#endif
Expand Down Expand Up @@ -153,7 +154,7 @@ in_mca(VOID_PARAM)
* Set up the display to start a new search command.
*/
static void
mca_search(VOID_PARAM)
mca_search1(VOID_PARAM)
{
#if HILITE_SEARCH
if (search_type & SRCH_FILTER)
Expand Down Expand Up @@ -188,6 +189,12 @@ mca_search(VOID_PARAM)
else
cmd_putstr("?");
forw_prompt = 0;
}

static void
mca_search(VOID_PARAM)
{
mca_search1();
set_mlist(ml_search, 0);
}

Expand Down Expand Up @@ -682,6 +689,12 @@ mca_char(c)
/* Incremental search: do a search after every input char. */
int st = (search_type & (SRCH_FORW|SRCH_BACK|SRCH_NO_MATCH|SRCH_NO_REGEX|SRCH_NO_MOVE|SRCH_WRAP));
char *pattern = get_cmdbuf();
/*
* Must save updown_match because mca_search
* reinits it. That breaks history scrolling.
* {{ This is ugly. mca_search probably shouldn't call set_mlist. }}
*/
int save_updown_match = updown_match;
cmd_exec();
if (*pattern == '\0')
{
Expand All @@ -694,7 +707,8 @@ mca_char(c)
undo_search(1);
}
/* Redraw the search prompt and search string. */
mca_search();
mca_search1();
updown_match = save_updown_match;
cmd_repaint(NULL);
}
break;
Expand Down

0 comments on commit 440f178

Please sign in to comment.