From e9c5fb3048c47eb8e2f3fa436750f5ae53da75e3 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Fri, 26 Sep 2014 11:11:11 +0400 Subject: [PATCH] (mcview_offset_doz): use more. --- src/viewer/inlines.h | 1 + src/viewer/move.c | 21 +++++++-------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/viewer/inlines.h b/src/viewer/inlines.h index 2a25c63f7..fbe3afd0c 100644 --- a/src/viewer/inlines.h +++ b/src/viewer/inlines.h @@ -17,6 +17,7 @@ /*** inline functions ****************************************************************************/ +/* difference or zero */ static inline off_t mcview_offset_doz (off_t a, off_t b) { diff --git a/src/viewer/move.c b/src/viewer/move.c index 89bdb5ce0..8d601a595 100644 --- a/src/viewer/move.c +++ b/src/viewer/move.c @@ -180,10 +180,8 @@ mcview_move_down (mcview_t * view, off_t lines) { off_t i, limit; - if (last_byte >= (off_t) view->bytes_per_line) - limit = last_byte - view->bytes_per_line; - else - limit = 0; + limit = mcview_offset_doz (last_byte, (off_t) view->bytes_per_line); + for (i = 0; i < lines && view->hex_cursor < limit; i++) { view->hex_cursor += view->bytes_per_line; @@ -258,12 +256,8 @@ mcview_move_left (mcview_t * view, off_t columns) view->hexedit_lownibble = !view->hexedit_lownibble; } else - { - if (view->dpy_text_column >= columns) - view->dpy_text_column -= columns; - else - view->dpy_text_column = 0; - } + view->dpy_text_column = mcview_offset_doz (view->dpy_text_column, columns); + mcview_movement_fixups (view, FALSE); } @@ -276,6 +270,7 @@ mcview_move_right (mcview_t * view, off_t columns) { off_t last_byte; off_t old_cursor = view->hex_cursor; + last_byte = mcview_offset_doz (mcview_get_filesize (view), 1); #ifdef HAVE_ASSERT_H assert (columns == 1); @@ -410,10 +405,8 @@ mcview_moveto_eol (mcview_t * view) if (eol > bol) view->dpy_text_column = eol - bol; - if (view->dpy_text_column < (off_t) view->data_area.width) - view->dpy_text_column = 0; - else - view->dpy_text_column = view->dpy_text_column - (off_t) view->data_area.width; + view->dpy_text_column = + mcview_offset_doz (view->dpy_text_column, (off_t) view->data_area.width); } mcview_movement_fixups (view, FALSE); }