From 60a5fce0f09d51ebfefb51a2c757391ccbff488e Mon Sep 17 00:00:00 2001 From: Fabienne Ducroquet Date: Tue, 17 Dec 2013 20:58:47 +0100 Subject: [PATCH] Add a function to put the current line at the top of the screen Signed-off-by: Fabienne Ducroquet --- src/config/actions-main.inc | 1 + src/viewer/action.c | 4 ++++ src/viewer/text/view.c | 6 ++++++ src/viewer/text/view.h | 1 + 4 files changed, 12 insertions(+) diff --git a/src/config/actions-main.inc b/src/config/actions-main.inc index cb6c6bbb..2e90ddc9 100644 --- a/src/config/actions-main.inc +++ b/src/config/actions-main.inc @@ -53,6 +53,7 @@ ACTION_(MAIN, "lua-console", LUA_CONSOLE, N__("Open a Lua console"), ACTION_REST ACTION_(MAIN, "mark-goto", MARK_GOTO, N__("Go at a specified mark"), ACTION_REQUIRE_VIEW_STATE), ACTION_(MAIN, "mark-set", MARK_SET, N__("Set a mark"), ACTION_REQUIRE_VIEW_STATE), ACTION_(MAIN, "menu", MENU, N__("Activate the menu"), 0), +ACTION_(MAIN, "move-current-top", MOVE_CURRENT_TOP, N__("Move downwards to put the current line at the top"), ACTION_REQUIRE_VIEW_STATE), ACTION_(MAIN, "move-cursor-down", MOVE_CURSOR_DOWN, N__("Move cursor down"), ACTION_REQUIRE_VIEW_STATE), ACTION_(MAIN, "move-cursor-left", MOVE_CURSOR_LEFT, N__("Move cursor left"), ACTION_REQUIRE_VIEW_STATE), ACTION_(MAIN, "move-cursor-line-start", MOVE_CURSOR_LINE_START, N__("Move cursor to the start of the line"), ACTION_REQUIRE_VIEW_STATE), diff --git a/src/viewer/action.c b/src/viewer/action.c index 402c4e12..d33a4c88 100644 --- a/src/viewer/action.c +++ b/src/viewer/action.c @@ -335,6 +335,10 @@ do_action(struct session *ses, enum main_action action_id, int verbose) activate_bfu_technology(ses, -1); break; + case ACT_MAIN_MOVE_CURRENT_TOP: + status = move_current_top(ses, doc_view); + break; + case ACT_MAIN_MOVE_CURSOR_UP: status = move_cursor_up(ses, doc_view); break; diff --git a/src/viewer/text/view.c b/src/viewer/text/view.c index 8eb422d3..943bd33e 100644 --- a/src/viewer/text/view.c +++ b/src/viewer/text/view.c @@ -138,6 +138,12 @@ move_half_page_down(struct session *ses, struct document_view *doc_view) return move_part_page_down(ses, doc_view, doc_view->box.height / 2); } +enum frame_event_status +move_current_top(struct session *ses, struct document_view *doc_view) +{ + return move_part_page_down(ses, doc_view, doc_view->box.height - ses->tab->y + 1); +} + /*! @a type == 0 -> PAGE_UP; * @a type == 1 -> UP */ static void diff --git a/src/viewer/text/view.h b/src/viewer/text/view.h index f7032f20..d560bb5e 100644 --- a/src/viewer/text/view.h +++ b/src/viewer/text/view.h @@ -14,6 +14,7 @@ struct terminal; * But doesn't free() the @a doc_view. */ void detach_formatted(struct document_view *doc_view); +enum frame_event_status move_current_top(struct session *ses, struct document_view *doc_view); enum frame_event_status move_page_down(struct session *ses, struct document_view *doc_view); enum frame_event_status move_half_page_down(struct session *ses, struct document_view *doc_view); enum frame_event_status move_page_up(struct session *ses, struct document_view *doc_view);