diff options
-rw-r--r-- | miscutils/less.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/miscutils/less.c b/miscutils/less.c index 3db7c9cdb..b0e2754f8 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
@@ -342,6 +342,23 @@ static void status_print(void) | |||
342 | print_hilite(p); | 342 | print_hilite(p); |
343 | } | 343 | } |
344 | 344 | ||
345 | static void cap_cur_fline(int nlines) | ||
346 | { | ||
347 | int diff; | ||
348 | if (cur_fline < 0) | ||
349 | cur_fline = 0; | ||
350 | if (cur_fline + max_displayed_line > max_fline + TILDES) { | ||
351 | cur_fline -= nlines; | ||
352 | if (cur_fline < 0) | ||
353 | cur_fline = 0; | ||
354 | diff = max_fline - (cur_fline + max_displayed_line) + TILDES; | ||
355 | /* As the number of lines requested was too large, we just move | ||
356 | to the end of the file */ | ||
357 | if (diff > 0) | ||
358 | cur_fline += diff; | ||
359 | } | ||
360 | } | ||
361 | |||
345 | static char controls[] = | 362 | static char controls[] = |
346 | /* NUL: never encountered; TAB: not converted */ | 363 | /* NUL: never encountered; TAB: not converted */ |
347 | /**/"\x01\x02\x03\x04\x05\x06\x07\x08" "\x0a\x0b\x0c\x0d\x0e\x0f" | 364 | /**/"\x01\x02\x03\x04\x05\x06\x07\x08" "\x0a\x0b\x0c\x0d\x0e\x0f" |
@@ -479,18 +496,9 @@ static void buffer_fill_and_print(void) | |||
479 | /* Move the buffer up and down in the file in order to scroll */ | 496 | /* Move the buffer up and down in the file in order to scroll */ |
480 | static void buffer_down(int nlines) | 497 | static void buffer_down(int nlines) |
481 | { | 498 | { |
482 | int diff; | ||
483 | cur_fline += nlines; | 499 | cur_fline += nlines; |
484 | read_lines(); | 500 | read_lines(); |
485 | 501 | cap_cur_fline(nlines); | |
486 | if (cur_fline + max_displayed_line > max_fline + TILDES) { | ||
487 | cur_fline -= nlines; | ||
488 | diff = max_fline - (cur_fline + max_displayed_line) + TILDES; | ||
489 | /* As the number of lines requested was too large, we just move | ||
490 | to the end of the file */ | ||
491 | if (diff > 0) | ||
492 | cur_fline += diff; | ||
493 | } | ||
494 | buffer_fill_and_print(); | 502 | buffer_fill_and_print(); |
495 | } | 503 | } |
496 | 504 | ||
@@ -763,6 +771,7 @@ static void goto_match(int match) | |||
763 | if (match >= num_matches && eof_error > 0) { | 771 | if (match >= num_matches && eof_error > 0) { |
764 | cur_fline = MAXLINES; /* look as far as needed */ | 772 | cur_fline = MAXLINES; /* look as far as needed */ |
765 | read_lines(); | 773 | read_lines(); |
774 | cap_cur_fline(cur_fline); | ||
766 | } | 775 | } |
767 | if (num_matches) { | 776 | if (num_matches) { |
768 | normalize_match_pos(match); | 777 | normalize_match_pos(match); |