Ticket #3258: fix incorrect percentage in mcview hex mode.

The percent in the upper right corner normally corresponds to the
cursor. Except when the bottom of the file is displayed, then it's
100%.

If the file is taller than the window, you can walk downwards to its
end and the percent is always correct. Then walk back a screenful and
it stays at 100%, and suddenly jumps back by a lot when the file starts
scrolling.

If the file is shorter than the window, it's always at 100%.

mcview_calc_percent() is supposed to calculate the percentage at offset
p, yet it executes a special branch when "dpy_end == filesize".

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Egmont Koblinger 2014-09-01 10:12:39 +04:00 committed by Andrew Borodin
parent 1aa16a0972
commit 584673c260

View File

@ -422,8 +422,13 @@ mcview_calc_percent (mcview_t * view, off_t p)
return (-1);
filesize = mcview_get_filesize (view);
if (view->hex_mode && filesize > 0)
{
/* p can't be beyond the last char, only over that. Compensate for this. */
filesize--;
}
if (filesize == 0 || view->dpy_end == filesize)
if (filesize == 0 || p >= filesize)
percent = 100;
else if (p > (INT_MAX / 100))
percent = p / (filesize / 100);