degesch: factor out buffer_remove_safe()

This commit is contained in:
Přemysl Eric Janouch 2015-07-14 06:11:14 +02:00
parent 1285ba2d13
commit 6f966d4aee
1 changed files with 11 additions and 6 deletions

View File

@ -3129,6 +3129,16 @@ buffer_get_index (struct app_context *ctx, struct buffer *buffer)
return -1;
}
static void
buffer_remove_safe (struct app_context *ctx, struct buffer *buffer)
{
if (buffer == ctx->current_buffer)
buffer_activate (ctx, ctx->last_buffer
? ctx->last_buffer
: buffer_next (ctx, 1));
buffer_remove (ctx, buffer);
}
static void
init_global_buffer (struct app_context *ctx)
{
@ -6718,12 +6728,7 @@ handle_buffer_close (struct app_context *ctx, struct handler_args *a)
// The user would be unable to recreate the buffer otherwise
if (buffer->type == BUFFER_CHANNEL)
part_channel (buffer->server, buffer->channel->name, "");
if (buffer == ctx->current_buffer)
buffer_activate (ctx, ctx->last_buffer
? ctx->last_buffer
: buffer_next (ctx, 1));
buffer_remove (ctx, buffer);
buffer_remove_safe (ctx, buffer);
}
}