Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Tue, 31 Aug 2021 10:24:31 UTC Commit: f1dff74db4844f8314420eea35c98335cb350559 https://github.com/geany/geany-plugins/commit/f1dff74db4844f8314420eea35c983...
Log Message: ----------- 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<esc>
we can reuse the code also for the '.' command.
Modified Paths: -------------- vimode/src/cmd-runner.c vimode/src/vi.c
Modified: vimode/src/cmd-runner.c 23 lines changed, 17 insertions(+), 6 deletions(-) =================================================================== @@ -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; }
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