Skip to content

Commit

Permalink
vimode: Ensure that the line with the cursor is expanded after perfor…
Browse files Browse the repository at this point in the history
…ming 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.
  • Loading branch information
techee committed May 21, 2024
1 parent 522b79d commit 33984ab
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions vimode/src/cmd-runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions vimode/src/excmd-runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 '?':
Expand All @@ -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;
}
}
Expand Down
8 changes: 8 additions & 0 deletions vimode/src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions vimode/src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 33984ab

Please sign in to comment.