From 440f1787b4d25e03749ae600d4612993c1bc6538 Mon Sep 17 00:00:00 2001 From: Mark Nudelman Date: Tue, 12 Oct 2021 16:27:41 -0700 Subject: [PATCH] Fix search history scrolling when --incsearch is set. --- cmdbuf.c | 2 +- command.c | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/cmdbuf.c b/cmdbuf.c index f4f8f3ea..cd99010d 100644 --- a/cmdbuf.c +++ b/cmdbuf.c @@ -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)); diff --git a/command.c b/command.c index c852d0e1..a6feaf57 100644 --- a/command.c +++ b/command.c @@ -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 @@ -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) @@ -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); } @@ -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') { @@ -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;