From 9eff3cef04ac6dc62c593ac427844ddc826b05fd Mon Sep 17 00:00:00 2001 From: Roland Illig Date: Thu, 14 Apr 2005 00:18:35 +0000 Subject: [PATCH] * view.c (view_move_forward2): Backed out my last changes. The old code worked better. :) --- src/ChangeLog | 5 +---- src/view.c | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index aadbd9db1..5aaabefe9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -24,16 +24,13 @@ * view.c (count_backspaces): Added a bounds check. * view.c (display): Using get_byte_indexed instead of get_byte. * view.c (move_forward2): Renamed to view_move_forward2 because - of the equally-named function in src/help.c. Replaced the - algorithm for the hexview mode by a much simpler version. Now - we have 5 ?: operators less than before. + of the equally-named function in src/help.c. * view.c (get_bottom_first): Added bounds checking. * view.c (move_right): Simplified the code. * view.c (goto_addr): Fixed an off-by-one error. * view.c (view_close_datasource): For the growing buffer cases, check if the datasource has already been closed before. * view.c (view_handle_editkey): Simplified the code. - * view.c (view_move_forward2): Simplified the code. * view.c (get_byte_growing_buffer): Added bounds checking. 2005-04-07 Roland Illig diff --git a/src/view.c b/src/view.c index a92e05e93..d27ea2b10 100644 --- a/src/view.c +++ b/src/view.c @@ -1137,20 +1137,28 @@ static offset_type view_move_forward2 (WView *view, offset_type current, int lines, offset_type upto) { const int frame_shift = view->have_frame; - const int bpl = view->bytes_per_line; - offset_type q, p, linestart; - int i, line; + offset_type q, p, last_byte; + int line; int col = 0; if (view->hex_mode) { - linestart = current - current % bpl; - /* try to move as many lines down as possible */ - for (i = lines; i != 0; i--) { - if (get_byte_indexed (view, linestart, i * bpl) != -1) - break; + last_byte = view_get_filesize (view); + p = current + lines * view->bytes_per_line; + p = (p >= last_byte) ? current : p; + if (lines == 1) { + q = view->edit_cursor + view->bytes_per_line; + line = q / view->bytes_per_line; + col = (last_byte - 1) / view->bytes_per_line; + view->edit_cursor = (line > col) ? view->edit_cursor : q; + view->edit_cursor = (view->edit_cursor < last_byte) ? + view->edit_cursor : last_byte - 1; + q = current + ((LINES - 2) * view->bytes_per_line); + p = (view->edit_cursor < q) ? current : p; + } else { + view->edit_cursor = (view->edit_cursor < p) ? + p : view->edit_cursor; } - view->edit_cursor += i * bpl; - return current + i * bpl; + return p; } else { if (upto) { lines = -1;