diff --git a/vimode/src/utils.c b/vimode/src/utils.c index ddd5c3f49..0b9c1de12 100644 --- a/vimode/src/utils.c +++ b/vimode/src/utils.c @@ -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; +} diff --git a/vimode/src/utils.h b/vimode/src/utils.h index b535cae81..017b8949b 100644 --- a/vimode/src/utils.h +++ b/vimode/src/utils.h @@ -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 diff --git a/vimode/src/vi.c b/vimode/src/vi.c index fae264854..d441c0bf8 100644 --- a/vimode/src/vi.c +++ b/vimode/src/vi.c @@ -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. */