Remove window before working out new current window; clear last window if necessary.

This commit is contained in:
Nicholas Marriott 2007-09-21 18:31:58 +00:00
parent 33f5f84f99
commit 248f78d29a

View File

@ -1,4 +1,4 @@
/* $Id: session.c,v 1.10 2007-09-21 18:16:31 nicm Exp $ */ /* $Id: session.c,v 1.11 2007-09-21 18:31:58 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -129,14 +129,13 @@ session_attach(struct session *s, struct window *w)
int int
session_detach(struct session *s, struct window *w) session_detach(struct session *s, struct window *w)
{ {
/* Move to last, previous of next window if possible. */ window_remove(&s->windows, w);
if (s->last == w)
s->last = NULL;
if (s->window == w && session_last(s) != 0 && session_previous(s) != 0) if (s->window == w && session_last(s) != 0 && session_previous(s) != 0)
session_next(s); session_next(s);
/* Remove the window from the list. */
window_remove(&s->windows, w);
/* Destroy session if it is empty. */
if (!ARRAY_EMPTY(&s->windows)) if (!ARRAY_EMPTY(&s->windows))
return (0); return (0);
session_destroy(s); session_destroy(s);