summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--degesch.c46
1 files changed, 21 insertions, 25 deletions
diff --git a/degesch.c b/degesch.c
index 1a54a95..4e67558 100644
--- a/degesch.c
+++ b/degesch.c
@@ -5435,6 +5435,24 @@ redraw_screen (struct app_context *ctx)
return true;
}
+static bool
+jump_to_buffer (struct app_context *ctx, int n)
+{
+ if (n < 0 || n > 9)
+ return false;
+
+ // There's no buffer zero
+ if (n == 0)
+ n = 10;
+
+ 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))
+ return false;
+ return true;
+}
+
static void
bind_common_keys (struct app_context *ctx)
{
@@ -5464,20 +5482,9 @@ on_readline_goto_buffer (int count, int key)
{
(void) count;
- int n = UNMETA (key) - '0';
- if (n < 0 || n > 9)
- return 0;
-
- // There's no buffer zero
- if (n == 0)
- n = 10;
-
struct app_context *ctx = g_ctx;
- 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))
- input_ding (self);
+ if (!jump_to_buffer (ctx, UNMETA (key) - '0'))
+ input_ding (&ctx->input);
return 0;
}
@@ -5610,19 +5617,8 @@ on_editline_goto_buffer (EditLine *editline, int key)
{
(void) editline;
- int n = key - '0';
- if (n < 0 || n > 9)
- return CC_ERROR;
-
- // There's no buffer zero
- if (n == 0)
- n = 10;
-
struct app_context *ctx = g_ctx;
- 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))
+ if (!jump_to_buffer (ctx, key - '0'))
return CC_ERROR;
return CC_NORM;
}