commit 55eb4d95383ce078ff680fc9c145359cc030b407 from: Omar Polo date: Thu Aug 12 08:32:38 2021 UTC new_tab: allow to add the tab after a current one this allows cmd_push_button_new_tab to open the new tab right *after* the current one, instead that always at the end. commit - bc55cdb9b8678689c6f39504ccf17cf1d0f943d5 commit + 55eb4d95383ce078ff680fc9c145359cc030b407 blob - 46a9b460d3f3c93beb6740d499fcfadd415807cd blob + 32c70afcbbdb043a9d5ad98b3447bb5f376e746b --- ChangeLog +++ ChangeLog @@ -1,4 +1,6 @@ 2021-08-12 Omar Polo + + * cmd.c (cmd_push_button_new_tab): open new tab right after the current one * telescope.c (load_url): improved reload command: it doesn't push the current url to the history anymore. blob - 767741497ace904ea7b086af834965318b22d7fd blob + 85eeb5aaa7f8fd829c100ba6bf310e716396cdfd --- cmd.c +++ cmd.c @@ -319,7 +319,7 @@ cmd_push_button_new_tab(struct buffer *buffer) if (vl == NULL || vl->parent->type != LINE_LINK) return; - new_tab(vl->parent->alt, current_tab->hist_cur->h); + new_tab(vl->parent->alt, current_tab->hist_cur->h, current_tab); } void @@ -477,7 +477,7 @@ cmd_tab_new(struct buffer *buffer) if ((url = new_tab_url) == NULL) url = NEW_TAB_URL; - new_tab(url, NULL); + new_tab(url, NULL, NULL); } void blob - 0bf6e95212e5111ca64597b50810501f53237a9b blob + d2223ed921f396012bb4c6436115abc2c3920096 --- telescope.c +++ telescope.c @@ -975,8 +975,8 @@ load_last_session(void) if ((session = fopen(session_file, "r")) == NULL) { /* first time? */ - new_tab("about:new", NULL); - switch_to_tab(new_tab("about:help", NULL)); + new_tab("about:new", NULL, NULL); + switch_to_tab(new_tab("about:help", NULL, NULL)); return; } @@ -984,7 +984,7 @@ load_last_session(void) if ((nl = strchr(line, '\n')) != NULL) *nl = '\0'; parse_session_line(line, &title, &flags); - if ((tab = new_tab(line, NULL)) == NULL) + if ((tab = new_tab(line, NULL, NULL)) == NULL) err(1, "new_tab"); strlcpy(tab->buffer.page.title, title, sizeof(tab->buffer.page.title)); @@ -1002,7 +1002,7 @@ load_last_session(void) switch_to_tab(curr); if (last_time_crashed()) - switch_to_tab(new_tab("about:crash", NULL)); + switch_to_tab(new_tab("about:crash", NULL, NULL)); return; } @@ -1200,7 +1200,7 @@ main(int argc, char * const *argv) if (ui_init()) { load_last_session(); if (has_url || TAILQ_EMPTY(&tabshead)) - new_tab(url, NULL); + new_tab(url, NULL, NULL); sandbox_ui_process(); ui_main_loop(); blob - 2c550124b6532106073abc2987c978dc57e8a631 blob + 3128c6590eb1ff0691854c1ef52ced466998746a --- ui.c +++ ui.c @@ -980,7 +980,7 @@ tab_new_id(void) } struct tab * -new_tab(const char *url, const char *base) +new_tab(const char *url, const char *base, struct tab *after) { struct tab *tab; @@ -999,10 +999,14 @@ new_tab(const char *url, const char *base) tab->flags |= TAB_LAZY; switch_to_tab(tab); - if (TAILQ_EMPTY(&tabshead)) - TAILQ_INSERT_HEAD(&tabshead, tab, tabs); - else - TAILQ_INSERT_TAIL(&tabshead, tab, tabs); + if (after != NULL) + TAILQ_INSERT_AFTER(&tabshead, after, tab, tabs); + else { + if (TAILQ_EMPTY(&tabshead)) + TAILQ_INSERT_HEAD(&tabshead, tab, tabs); + else + TAILQ_INSERT_TAIL(&tabshead, tab, tabs); + } load_url_in_tab(tab, url, base, 0); return tab; blob - d043c8026f06fcfa44dd26e43e5abc4f11700f9e blob + 0d4ad22b7005186c29b924d57b2036c982d33765 --- ui.h +++ ui.h @@ -125,7 +125,7 @@ void start_loading_anim(struct tab *); void load_url_in_tab(struct tab *, const char *, const char *, int); void switch_to_tab(struct tab *); struct buffer *current_buffer(void); -struct tab *new_tab(const char *, const char *base); +struct tab *new_tab(const char *, const char *base, struct tab *); unsigned int tab_new_id(void); int ui_print_colors(void);