[elinks-users] [PATCH] Add a function to put the current line at the top of the screen

Fabienne Ducroquet fabiduc at gmail.com
Tue Dec 17 11:58:47 PST 2013

Signed-off-by: Fabienne Ducroquet <fabiduc at gmail.com>

Le mardi 17 décembre 2013, Fabienne Ducroquet a écrit :
> Le dimanche 15 décembre 2013, Mayuresh a écrit :
> > Would it be possible to make a mouse gesture such as click or double click
> > on a line to make it become the top line of the view?
> It would not be difficult to define a function to put a given line at 
> the top, we just need the line’s y-position. Have a look at 
> src/viewer/text/view.c, or just at commit 
> 6211b8e725f95c3c0851e13a93dec4afdb6c1d4e where I added the 
> move-half-page-down/up commands.
> There are already functions to move the cursor up and down even if there 
> is no link so they could be used to select a line with the cursor and 
> put it at the top.
> There are functions that give the mouse position so I guess it would 
> be possible with the mouse too.

Here is a patch defining a function that puts the current line (the line 
where the currently selected link is or where the cursor is) at the top of 
the screen. It can be used only with a keyboard shortcut (undefined by 

I tried to make it work with the mouse too, but the problem is that ELinks 
seems to support only single clicks with 5 buttons, all the mouse events 
are already associated to functions and it’s hardcoded. It may be possible 
to associate that function to one click in a way that doesn’t interfere 
with the already defined mappings, but it’s not really intuitive to have 
a line move to the top when you click on it so I don’t think this should 
be hardcoded. This means that to allow the definition of a mouse gesture 
making a line the top line, it would be necessary to make the mapping of 
mouse events configurable so that’s more work than what I did.

 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 cb6c6bb..2e90ddc 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 402c4e1..d33a4c8 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);
+			status = move_current_top(ses, doc_view);
+			break;
 			status = move_cursor_up(ses, doc_view);
diff --git a/src/viewer/text/view.c b/src/viewer/text/view.c
index 8eb422d..943bd33 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 f7032f2..d560bb5 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);

More information about the elinks-users mailing list