From 33984abc9bd24bbf03db3ac517eb45ca2c7e6b7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Thu, 25 Apr 2024 16:06:22 +0200 Subject: [PATCH] vimode: Ensure that the line with the cursor is expanded after performing a command Without this, using e.g. 'w' to go to the next word makes the cursor go "inside" the fold and disappear. Vim seems to auto-expand the fold in such situations so do the same. --- vimode/src/cmd-runner.c | 1 + vimode/src/excmd-runner.c | 2 ++ vimode/src/utils.c | 8 ++++++++ vimode/src/utils.h | 1 + 4 files changed, 12 insertions(+) diff --git a/vimode/src/cmd-runner.c b/vimode/src/cmd-runner.c index 49706a539..43878c6c1 100644 --- a/vimode/src/cmd-runner.c +++ b/vimode/src/cmd-runner.c @@ -704,6 +704,7 @@ static gboolean process_cmd(CmdDef *cmds, CmdContext *ctx, gboolean ins_mode) { if (orig_mode == VI_MODE_COMMAND_SINGLE) vi_set_mode(VI_MODE_INSERT); + ensure_current_line_expanded(ctx->sci); } else if (!consumed && ctx->kpl) { diff --git a/vimode/src/excmd-runner.c b/vimode/src/excmd-runner.c index 663291813..4cca689df 100644 --- a/vimode/src/excmd-runner.c +++ b/vimode/src/excmd-runner.c @@ -465,6 +465,7 @@ void excmd_perform(CmdContext *ctx, const gchar *cmd) { case ':': perform_simple_ex_cmd(ctx, cmd + 1); + ensure_current_line_expanded(ctx->sci); break; case '/': case '?': @@ -483,6 +484,7 @@ void excmd_perform(CmdContext *ctx, const gchar *cmd) pos = perform_search(ctx->sci, ctx->search_text, ctx->num, FALSE); if (pos >= 0) SET_POS(ctx->sci, pos, TRUE); + ensure_current_line_expanded(ctx->sci); break; } } diff --git a/vimode/src/utils.c b/vimode/src/utils.c index b491a2dc1..2a367a80c 100644 --- a/vimode/src/utils.c +++ b/vimode/src/utils.c @@ -219,3 +219,11 @@ void goto_nonempty(ScintillaObject *sci, gint line, gboolean scroll) pos = NEXT(sci, pos); SET_POS(sci, pos, scroll); } + + +void ensure_current_line_expanded(ScintillaObject *sci) +{ + gint line = GET_CUR_LINE(sci); + if (!SSM(sci, SCI_GETLINEVISIBLE, line, 0)) + SSM(sci, SCI_ENSUREVISIBLE, line, 0); +} diff --git a/vimode/src/utils.h b/vimode/src/utils.h index e2e83d97c..b535cae81 100644 --- a/vimode/src/utils.h +++ b/vimode/src/utils.h @@ -32,5 +32,6 @@ void perform_substitute(ScintillaObject *sci, const gchar *cmd, gint from, gint const gchar *flag_override); gint get_line_number_rel(ScintillaObject *sci, gint shift); +void ensure_current_line_expanded(ScintillaObject *sci); #endif