1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

Don't let move_current_tab move the tab beyond the main menu.

src/terminal/tab.c (get_tab_by_number): Assert that the returned
struct window * actually points to a struct window.

src/terminal/tab.c (move_current_tab): Keep tabs contiguous in the
stack of windows.  Obey "ui.tabs.wraparound".

src/terminal/terminal.h (struct terminal): Documented that tabs can
move in the stack.

src/terminal/window.c (assert_window_stacking): Check that the main
menu isn't between tabs.
This commit is contained in:
Kalle Olavi Niemitalo 2006-05-14 22:17:26 +03:00 committed by Kalle Olavi Niemitalo
parent 276f723ab7
commit 39c157389d
3 changed files with 38 additions and 17 deletions

View File

@ -103,6 +103,12 @@ get_tab_by_number(struct terminal *term, int num)
num--; num--;
} }
/* Ensure that the return value actually points to a struct
* window. */
assertm((struct list_head *) win != &term->windows,
"tab number out of range");
if_assert_failed return term->windows.next;
return win; return win;
} }
@ -301,22 +307,27 @@ move_current_tab(struct session *ses, int direction)
new_pos = term->current_tab + direction; new_pos = term->current_tab + direction;
while (new_pos < 1 || new_pos > tabs) if (get_opt_bool("ui.tabs.wraparound")) {
new_pos += new_pos < 1 ? tabs : -tabs; while (new_pos < 0 || new_pos >= tabs)
new_pos += new_pos < 0 ? tabs : -tabs;
assert(0 < new_pos && new_pos <= tabs); } else {
if (new_pos < 0)
new_pos = 0;
else if (new_pos >= tabs)
new_pos = tabs - 1;
}
assert(0 <= new_pos && new_pos < tabs);
/* This protects against tabs==1 and optimizes an unusual case. */
if (new_pos == term->current_tab) return; if (new_pos == term->current_tab) return;
tab = get_tab_by_number(term, new_pos);
del_from_list(current_tab); del_from_list(current_tab);
if (new_pos == 0) {
if (new_pos < term->current_tab) { tab = get_tab_by_number(term, 0);
add_at_pos(tab, current_tab);
} else { } else {
add_to_list_end(*tab, current_tab); tab = get_tab_by_number(term, new_pos-1)->prev;
} }
add_at_pos(tab, current_tab);
switch_to_tab(term, new_pos, tabs); switch_to_tab(term, new_pos, tabs);
} }

View File

@ -73,9 +73,9 @@ struct terminal {
* current window; and .prev is the bottom, covered by others. * current window; and .prev is the bottom, covered by others.
* - Dialogs or active menus are at the top. * - Dialogs or active menus are at the top.
* - Next come all tabs (window.type == WINDOW_TAB). The tab * - Next come all tabs (window.type == WINDOW_TAB). The tab
* created last is at the top, and the tab created first is * listed leftmost in the tab bar is at the top, and the tab
* at the bottom; but current_tab controls which tab is * listed rightmost is at the bottom; but current_tab controls
* actually displayed. * which tab is actually displayed.
* - If the main menu is inactive, then it is at the very bottom, * - If the main menu is inactive, then it is at the very bottom,
* hidden under the tabs. * hidden under the tabs.
* Call assert_window_stacking to verify this. * Call assert_window_stacking to verify this.

View File

@ -178,7 +178,7 @@ add_empty_window(struct terminal *term, void (*fn)(void *), void *data)
void void
assert_window_stacking(struct terminal *term) assert_window_stacking(struct terminal *term)
{ {
int prev_type = WINDOW_NORMAL; enum { WANT_ANY, WANT_TAB, WANT_NONE } want = WANT_ANY;
const struct window *win; const struct window *win;
const struct window *main_menu_win; const struct window *main_menu_win;
@ -186,10 +186,20 @@ assert_window_stacking(struct terminal *term)
main_menu_win = term->main_menu ? term->main_menu->win : NULL; main_menu_win = term->main_menu ? term->main_menu->win : NULL;
foreach (win, term->windows) { foreach (win, term->windows) {
if (win != main_menu_win) { switch (want) {
if (prev_type == WINDOW_TAB) case WANT_ANY:
if (win->type == WINDOW_TAB)
want = WANT_TAB;
break;
case WANT_TAB:
if (win == main_menu_win)
want = WANT_NONE;
else
assert(win->type == WINDOW_TAB); assert(win->type == WINDOW_TAB);
prev_type = win->type; break;
case WANT_NONE:
assert(0);
break;
} }
} }
} }