Skip to content

Commit

Permalink
Merge pull request #1349 from scresto09/vimode-handle-fold-marginclick
Browse files Browse the repository at this point in the history
Vimode: handle fold and margin click event
  • Loading branch information
techee authored May 24, 2024
2 parents 0e299a8 + fade2b7 commit 7da7553
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
25 changes: 25 additions & 0 deletions vimode/src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,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 @@ -312,6 +312,15 @@ gboolean vi_notify_sci(SCNotification *nt)
if (nt->nmhdr.code == SCN_MODIFIED && (nt->modificationType & SC_MOD_BEFOREINSERT && nt->modificationType & SC_PERFORMED_UNDO) && nt->length > 1)
undo_update(&ctx, nt->position);

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 7da7553

Please sign in to comment.