From 798a7cc4e63f631581b8674309042267f85c1bba Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sun, 15 Apr 2018 14:32:18 +0200 Subject: [PATCH] Reuse existing functions to scroll. Added horizontal_scroll_extended. --- src/viewer/text/search.c | 7 +++---- src/viewer/text/view.c | 19 +++++++++++++++---- src/viewer/text/view.h | 2 ++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/viewer/text/search.c b/src/viewer/text/search.c index e1b8f40fc..3f5e1a799 100644 --- a/src/viewer/text/search.c +++ b/src/viewer/text/search.c @@ -1312,6 +1312,7 @@ move_search_do(struct session *ses, struct document_view *doc_view, int directio return FRAME_EVENT_REFRESH; } + enum frame_event_status move_search_next(struct session *ses, struct document_view *doc_view) { @@ -1340,10 +1341,8 @@ move_search_number(struct session *ses, struct document_view *doc_view, int numb x = pt[number].x; y = pt[number].y; - if (x < doc_view->vs->x || x >= doc_view->vs->x + doc_view->box.width) - doc_view->vs->x = x; - doc_view->vs->y = y; - set_link(doc_view); + horizontal_scroll_extended(ses, doc_view, x - doc_view->vs->x, 0); + vertical_scroll(ses, doc_view, y - doc_view->vs->y); return FIND_ERROR_NONE; } diff --git a/src/viewer/text/view.c b/src/viewer/text/view.c index ec3422ce2..3192285f8 100644 --- a/src/viewer/text/view.c +++ b/src/viewer/text/view.c @@ -300,7 +300,7 @@ move_link_dir(struct session *ses, struct document_view *doc_view, int dir_x, in } /*! @a steps > 0 -> down */ -static enum frame_event_status +enum frame_event_status vertical_scroll(struct session *ses, struct document_view *doc_view, int steps) { int y; @@ -335,8 +335,8 @@ vertical_scroll(struct session *ses, struct document_view *doc_view, int steps) } /*! @a steps > 0 -> right */ -static enum frame_event_status -horizontal_scroll(struct session *ses, struct document_view *doc_view, int steps) +enum frame_event_status +horizontal_scroll_extended(struct session *ses, struct document_view *doc_view, int steps, int extended) { int x, max; @@ -345,7 +345,7 @@ horizontal_scroll(struct session *ses, struct document_view *doc_view, int steps x = doc_view->vs->x + steps; - if (get_opt_bool("document.browse.scrolling.horizontal_extended", ses)) { + if (extended) { max = doc_view->document->width - 1; } else { max = int_max(doc_view->vs->x, @@ -365,6 +365,17 @@ horizontal_scroll(struct session *ses, struct document_view *doc_view, int steps return FRAME_EVENT_REFRESH; } +/*! @a steps > 0 -> right */ +static enum frame_event_status +horizontal_scroll(struct session *ses, struct document_view *doc_view, int steps) +{ + assert(ses && doc_view && doc_view->vs && doc_view->document); + if_assert_failed return FRAME_EVENT_OK; + + return horizontal_scroll_extended(ses, doc_view, steps, + get_opt_bool("document.browse.scrolling.horizontal_extended", ses)); +} + enum frame_event_status scroll_up(struct session *ses, struct document_view *doc_view) { diff --git a/src/viewer/text/view.h b/src/viewer/text/view.h index 1593166b5..c598608bf 100644 --- a/src/viewer/text/view.h +++ b/src/viewer/text/view.h @@ -42,6 +42,8 @@ enum frame_event_status scroll_up(struct session *ses, struct document_view *doc enum frame_event_status scroll_down(struct session *ses, struct document_view *doc_view); enum frame_event_status scroll_left(struct session *ses, struct document_view *doc_view); enum frame_event_status scroll_right(struct session *ses, struct document_view *doc_view); +enum frame_event_status horizontal_scroll_extended(struct session *ses, struct document_view *doc_view, int steps, int extended); +enum frame_event_status vertical_scroll(struct session *ses, struct document_view *doc_view, int steps); enum frame_event_status move_document_start(struct session *ses, struct document_view *doc_view); enum frame_event_status move_document_end(struct session *ses, struct document_view *doc_view);