Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vimode: handle fold and margin click event #1349

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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