Skip to content

Commit

Permalink
Vimode: handle fold and margin click event
Browse files Browse the repository at this point in the history
  • Loading branch information
scresto09 committed May 24, 2024
1 parent 23d0a58 commit d861058
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
26 changes: 26 additions & 0 deletions vimode/src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ gint get_line_number_rel(ScintillaObject *sci, gint shift)
return new_line;
}


void goto_nonempty(ScintillaObject *sci, gint line, gboolean scroll)
{
gint line_end_pos = SSM(sci, SCI_GETLINEENDPOSITION, line, 0);
Expand All @@ -227,3 +228,28 @@ void ensure_current_line_expanded(ScintillaObject *sci)
if (!SSM(sci, SCI_GETLINEVISIBLE, line, 0))
SSM(sci, SCI_ENSUREVISIBLE, line, 0);
}


gint jump_to_expended_parent(ScintillaObject *sci, gint line)
{
gint fold_parent = line;

/* go through the parents as long as they are not visible */
while (SSM(sci, SCI_GETLINEVISIBLE, fold_parent, 0) == FALSE)
{
gint prev_parent = SSM(sci, SCI_GETFOLDPARENT, fold_parent, 0);

if (prev_parent == -1)
break;
fold_parent = prev_parent;
}

if (fold_parent != line)
{
/* move the cursor on the visible line before the fold */
gint pos = SSM(sci, SCI_POSITIONFROMLINE, fold_parent, 0);
SET_POS(sci, pos, TRUE);
}

return fold_parent;
}
2 changes: 2 additions & 0 deletions vimode/src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ void perform_substitute(ScintillaObject *sci, const gchar *cmd, gint from, gint
gint get_line_number_rel(ScintillaObject *sci, gint shift);
void ensure_current_line_expanded(ScintillaObject *sci);

gint jump_to_expended_parent(ScintillaObject *sci, gint line);

#endif
9 changes: 9 additions & 0 deletions vimode/src/vi.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,15 @@ gboolean vi_notify_sci(SCNotification *nt)
}
}

if (nt->nmhdr.code == SCN_MARGINCLICK)
{
if (nt->margin == 2)
{
gint line = GET_CUR_LINE(sci);
jump_to_expended_parent(sci, line);
}
}

/* This makes sure that when we click behind the end of line in command mode,
* the cursor is not placed BEHIND the last character but ON the last character.
* We want to ignore this when doing selection with mouse as it breaks things. */
Expand Down

0 comments on commit d861058

Please sign in to comment.