diff options
author | Denys Vlasenko | 2016-08-16 15:27:30 +0200 |
---|---|---|
committer | Denys Vlasenko | 2016-08-16 15:27:30 +0200 |
commit | 110c6bb413ff7363e9b453edef8ae11cf7b64404 (patch) | |
tree | ce1025c1e15c6be971498d3d60fb46c5bc83e314 | |
parent | 252559601f12e22ad3a687fb8188fdbf63bbdc45 (diff) | |
download | busybox-110c6bb413ff7363e9b453edef8ae11cf7b64404.zip busybox-110c6bb413ff7363e9b453edef8ae11cf7b64404.tar.gz |
less: fix bracket search to match behavior of less 481
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/less.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/miscutils/less.c b/miscutils/less.c index 10e1d8e..d1d4a71 100644 --- a/miscutils/less.c +++ b/miscutils/less.c @@ -1589,18 +1589,23 @@ static char opp_bracket(char bracket) static void match_right_bracket(char bracket) { - unsigned i; + unsigned i = cur_fline; - if (cur_fline >= max_fline - || strchr(flines[cur_fline], bracket) == NULL + if (i >= max_fline + || strchr(flines[i], bracket) == NULL ) { print_statusline("No bracket in top line"); return; } + bracket = opp_bracket(bracket); - for (i = cur_fline + 1; i < max_fline; i++) { + for (; i < max_fline; i++) { if (strchr(flines[i], bracket) != NULL) { - buffer_line(i); + /* + * Line with matched right bracket becomes + * last visible line + */ + buffer_line(i - max_displayed_line); return; } } @@ -1609,18 +1614,22 @@ static void match_right_bracket(char bracket) static void match_left_bracket(char bracket) { - int i; + int i = cur_fline + max_displayed_line; - if (cur_fline + max_displayed_line >= max_fline - || strchr(flines[cur_fline + max_displayed_line], bracket) == NULL + if (i >= max_fline + || strchr(flines[i], bracket) == NULL ) { print_statusline("No bracket in bottom line"); return; } bracket = opp_bracket(bracket); - for (i = cur_fline + max_displayed_line; i >= 0; i--) { + for (; i >= 0; i--) { if (strchr(flines[i], bracket) != NULL) { + /* + * Line with matched left bracket becomes + * first visible line + */ buffer_line(i); return; } |