From d894f563d00050b6aac657c49cc262378613535c Mon Sep 17 00:00:00 2001 From: sgerwk Date: Sat, 13 Mar 2021 09:58:09 +0100 Subject: [PATCH] optionally, going back from initial page closes tab or elinks --- src/config/options.inc | 4 ++++ src/session/history.c | 8 ++++++-- src/session/history.h | 2 +- src/viewer/action.c | 4 +++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/config/options.inc b/src/config/options.inc index 3b82ecde..9c2c7641 100644 --- a/src/config/options.inc +++ b/src/config/options.inc @@ -1488,6 +1488,10 @@ static union option_info config_options_info[] = { "Changes take effect at the next elinks restart.")), #endif + INIT_OPT_BOOL("ui", N_("Back to exit"), + "back_to_exit", 0, 0, + N_("Going back from initial page exits tab or elinks.")), + INIT_OPT_BOOL("ui", N_("Set window title"), "window_title", 0, 1, N_("Set the window title when running in a windowing " diff --git a/src/session/history.c b/src/session/history.c index b07a23d8..dc52f8da 100644 --- a/src/session/history.c +++ b/src/session/history.c @@ -165,12 +165,13 @@ go_history(struct session *ses, struct location *loc) CACHE_MODE_ALWAYS, TASK_HISTORY, 0); } -void +int go_history_by_n(struct session *ses, int n) { struct location *loc = cur_loc(ses); - if (!loc) return; + if (!loc) + return -1; if (n > 0) { while (n-- && list_has_next(ses->history.history, loc)) @@ -178,9 +179,12 @@ go_history_by_n(struct session *ses, int n) } else { while (n++ && list_has_prev(ses->history.history, loc)) loc = loc->prev; + if (n == 0 && ! list_has_prev(ses->history.history, loc)) + return -1; } go_history(ses, loc); + return 0; } /** Go backward in the history. See go_history() description regarding diff --git a/src/session/history.h b/src/session/history.h index 566bc322..ea481261 100644 --- a/src/session/history.h +++ b/src/session/history.h @@ -40,7 +40,7 @@ void go_history(struct session *ses, struct location *loc); /** Move back -@a n times if @a n is negative, forward @a n times if * positive. */ -void go_history_by_n(struct session *ses, int n); +int go_history_by_n(struct session *ses, int n); void go_back(struct session *ses); void go_unback(struct session *ses); diff --git a/src/viewer/action.c b/src/viewer/action.c index 0a7df2c9..09c1e57d 100644 --- a/src/viewer/action.c +++ b/src/viewer/action.c @@ -255,7 +255,9 @@ do_action(struct session *ses, enum main_action action_id, int verbose) { int count = int_max(1, eat_kbd_repeat_count(ses)); - go_history_by_n(ses, -count); + if (go_history_by_n(ses, -count) && + get_opt_bool("ui.back_to_exit", NULL)) + close_tab(term, ses); break; } case ACT_MAIN_HISTORY_MOVE_FORWARD: