From f1dff74db4844f8314420eea35c98335cb350559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Tue, 31 Aug 2021 03:22:08 -0700 Subject: [PATCH 1/2] vimode: Enable '.' to also repeat last inserted text Currently, '.' only repeats the last command inserted in the command mode and doesn't repeat text inserted in the (just exited) insert mode which vim does. Since we already support commands like 10iwrite_text_to_be_repeated_10_times we can reuse the code also for the '.' command. --- vimode/src/cmd-runner.c | 23 +++++++++++++++++------ vimode/src/vi.c | 6 ++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/vimode/src/cmd-runner.c b/vimode/src/cmd-runner.c index 2dc315402..e8f2ad30f 100644 --- a/vimode/src/cmd-runner.c +++ b/vimode/src/cmd-runner.c @@ -611,14 +611,25 @@ static gboolean perform_repeat_cmd(CmdContext *ctx) gint i; def = get_cmd_to_run(ctx->repeat_kpl, edit_cmds, FALSE); - if (!def) - return FALSE; - num = num == -1 ? 1 : num; - for (i = 0; i < num; i++) - perform_cmd(def, ctx); + if (def) { + for (i = 0; i < num; i++) + perform_cmd(def, ctx); + return TRUE; + } + else if (ctx->insert_buf_len > 0) { + gint pos; + + SSM(ctx->sci, SCI_BEGINUNDOACTION, 0, 0); + for (i = 0; i < num; i++) + SSM(ctx->sci, SCI_ADDTEXT, ctx->insert_buf_len, (sptr_t) ctx->insert_buf); + pos = SSM(ctx->sci, SCI_GETCURRENTPOS, 0, 0); + SET_POS(ctx->sci, PREV(ctx->sci, pos), FALSE); + SSM(ctx->sci, SCI_ENDUNDOACTION, 0, 0); + return TRUE; + } - return TRUE; + return FALSE; } diff --git a/vimode/src/vi.c b/vimode/src/vi.c index bf7d65e1e..f5b6c9496 100644 --- a/vimode/src/vi.c +++ b/vimode/src/vi.c @@ -109,8 +109,6 @@ static void repeat_insert(gboolean replace) SSM(sci, SCI_ENDUNDOACTION, 0, 0); } ctx.num = 1; - ctx.insert_buf_len = 0; - ctx.insert_buf[0] = '\0'; ctx.newline_insert = FALSE; } @@ -156,6 +154,10 @@ void vi_set_mode(ViMode mode) gint start_pos = SSM(sci, SCI_POSITIONFROMLINE, GET_CUR_LINE(sci), 0); if (pos > start_pos) SET_POS(sci, PREV(sci, pos), FALSE); + + /* erase kpl so '.' command repeats last inserted text and not command */ + g_slist_free_full(ctx.kpl, g_free); + ctx.kpl = NULL; } else if (VI_IS_VISUAL(prev_mode)) SSM(sci, SCI_SETEMPTYSELECTION, pos, 0); From 25291ea004e3430d1ad8947d90f552e5d40456fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Tue, 7 Sep 2021 04:06:10 -0700 Subject: [PATCH 2/2] vimode: increase the size of the buffer for recording insert mode text This should be more than enough for manually inserted text and a reasonable amount for pasted text. --- vimode/src/context.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vimode/src/context.h b/vimode/src/context.h index 3d60b39aa..d25573c9b 100644 --- a/vimode/src/context.h +++ b/vimode/src/context.h @@ -22,7 +22,7 @@ #include "vi.h" #include "sci.h" -#define INSERT_BUF_LEN 4096 +#define INSERT_BUF_LEN 131072 typedef struct { @@ -54,7 +54,7 @@ typedef struct gint num; /* buffer used in insert/replace mode to record entered text so it can be - * copied N times when e.g. 'i' is preceded by a number */ + * copied N times when e.g. 'i' is preceded by a number or when using '.' */ gchar insert_buf[INSERT_BUF_LEN]; gint insert_buf_len; } CmdContext;