Branch: refs/heads/master Author: Frank Lanitz frank@frank.uvena.de Committer: GitHub noreply@github.com Date: Wed, 29 Sep 2021 17:11:12 UTC Commit: 00c2a030e722cda45d7ce77e1b8431a773f49b77 https://github.com/geany/geany-plugins/commit/00c2a030e722cda45d7ce77e1b8431...
Log Message: ----------- Merge pull request #1102 from techee/vim_repeat_insert
vimode: Enable '.' to also repeat last inserted text
Modified Paths: -------------- vimode/src/cmd-runner.c vimode/src/context.h vimode/src/vi.c
Modified: vimode/src/cmd-runner.c 23 lines changed, 17 insertions(+), 6 deletions(-) =================================================================== @@ -633,14 +633,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; }
Modified: vimode/src/context.h 4 lines changed, 2 insertions(+), 2 deletions(-) =================================================================== @@ -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;
Modified: vimode/src/vi.c 6 lines changed, 4 insertions(+), 2 deletions(-) =================================================================== @@ -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);
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
plugins-commits@lists.geany.org