aboutsummaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/degesch.c b/degesch.c
index f6827ed..1d5e3ee 100644
--- a/degesch.c
+++ b/degesch.c
@@ -482,6 +482,8 @@ struct app_context
struct buffer *buffers; ///< All our buffers in order
struct buffer *buffers_tail; ///< The tail of our buffers
+ struct buffer *last_buffer; ///< Last used buffer
+
// XXX: when we go multiserver, there will be collisions
// TODO: make buffer names unique like weechat does
struct str_map buffers_by_name; ///< Excludes GLOBAL and SERVER
@@ -1425,6 +1427,9 @@ buffer_remove (struct app_context *ctx, struct buffer *buffer)
LIST_UNLINK_WITH_TAIL (ctx->buffers, ctx->buffers_tail, buffer);
buffer_destroy (buffer);
+ if (buffer == ctx->last_buffer)
+ ctx->last_buffer = NULL;
+
// It's not a good idea to remove these buffers, but it's even a worse
// one to leave the pointers point to invalid memory
if (buffer == ctx->global_buffer)
@@ -1515,6 +1520,7 @@ buffer_activate (struct app_context *ctx, struct buffer *buffer)
}
// Now at last we can switch the pointers
+ ctx->last_buffer = ctx->current_buffer;
ctx->current_buffer = buffer;
refresh_prompt (ctx);
@@ -2178,8 +2184,15 @@ on_readline_goto_buffer (int count, int key)
if (n < 0 || n > 9)
return 0;
+ // There's no buffer zero
+ if (n == 0)
+ n = 10;
+
struct app_context *ctx = g_ctx;
- if (!buffer_goto (ctx, n == 0 ? 10 : n))
+ if (ctx->last_buffer && buffer_get_index (ctx, ctx->current_buffer) == n)
+ // Fast switching between two buffers
+ buffer_activate (ctx, ctx->last_buffer);
+ else if (!buffer_goto (ctx, n == 0 ? 10 : n))
rl_ding ();
return 0;
}