diff --git a/src/viewer/lib.c b/src/viewer/lib.c index a45c0353e..6863dff3b 100644 --- a/src/viewer/lib.c +++ b/src/viewer/lib.c @@ -130,8 +130,8 @@ mcview_toggle_hex_mode (mcview_t * view) } else { - view->dpy_start = view->hex_cursor; - mcview_moveto_bol (view); + view->dpy_start = mcview_bol (view, view->hex_cursor, 0); + view->hex_cursor = view->dpy_start; widget_want_cursor (view->widget, 0); } mcview_altered_hex_mode = 1; @@ -239,7 +239,9 @@ mcview_done (mcview_t * view) vfs_path_t *vpath; vpath = vfs_path_from_str (view->filename); canon_fname = vfs_path_to_str (vpath); - save_file_position (canon_fname, -1, 0, view->dpy_start, view->saved_bookmarks); + save_file_position (canon_fname, -1, 0, + view->hex_mode ? view->hex_cursor : view->dpy_start, + view->saved_bookmarks); view->saved_bookmarks = NULL; g_free (canon_fname); vfs_path_free (vpath); diff --git a/src/viewer/mcviewer.c b/src/viewer/mcviewer.c index 055078f7d..a67895b11 100644 --- a/src/viewer/mcviewer.c +++ b/src/viewer/mcviewer.c @@ -386,14 +386,24 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l { char *canon_fname; long line, col; - off_t new_offset; + off_t new_offset, max_offset; vfs_path_t *vpath; vpath = vfs_path_from_str (view->filename); canon_fname = vfs_path_to_str (vpath); load_file_position (canon_fname, &line, &col, &new_offset, &view->saved_bookmarks); - new_offset = min (new_offset, mcview_get_filesize (view)); - view->dpy_start = mcview_bol (view, new_offset, 0); + max_offset = mcview_get_filesize (view) - 1; + if (max_offset < 0) + new_offset = 0; + else + new_offset = min (new_offset, max_offset); + if (!view->hex_mode) + view->dpy_start = mcview_bol (view, new_offset, 0); + else + { + view->dpy_start = new_offset - new_offset % view->bytes_per_line; + view->hex_cursor = new_offset; + } g_free (canon_fname); vfs_path_free (vpath); }