degesch: factor out jump_to_buffer()
This commit is contained in:
parent
102df84cfc
commit
6414a73d62
46
degesch.c
46
degesch.c
@ -5435,6 +5435,24 @@ redraw_screen (struct app_context *ctx)
|
|||||||
return true;
|
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
|
static void
|
||||||
bind_common_keys (struct app_context *ctx)
|
bind_common_keys (struct app_context *ctx)
|
||||||
{
|
{
|
||||||
@ -5464,20 +5482,9 @@ on_readline_goto_buffer (int count, int key)
|
|||||||
{
|
{
|
||||||
(void) count;
|
(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;
|
struct app_context *ctx = g_ctx;
|
||||||
if (ctx->last_buffer && buffer_get_index (ctx, ctx->current_buffer) == n)
|
if (!jump_to_buffer (ctx, UNMETA (key) - '0'))
|
||||||
// Fast switching between two buffers
|
input_ding (&ctx->input);
|
||||||
buffer_activate (ctx, ctx->last_buffer);
|
|
||||||
else if (!buffer_goto (ctx, n))
|
|
||||||
input_ding (self);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5610,19 +5617,8 @@ on_editline_goto_buffer (EditLine *editline, int key)
|
|||||||
{
|
{
|
||||||
(void) editline;
|
(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;
|
struct app_context *ctx = g_ctx;
|
||||||
if (ctx->last_buffer && buffer_get_index (ctx, ctx->current_buffer) == n)
|
if (!jump_to_buffer (ctx, key - '0'))
|
||||||
// Fast switching between two buffers
|
|
||||||
buffer_activate (ctx, ctx->last_buffer);
|
|
||||||
else if (!buffer_goto (ctx, n))
|
|
||||||
return CC_ERROR;
|
return CC_ERROR;
|
||||||
return CC_NORM;
|
return CC_NORM;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user