Skip to content
Browse files

Improve collapsing fold behaviour when start point is offscreen

When collapsing a fold range whose starting line is offscreen,
scroll the starting line to display at the top of the view.
Otherwise it can be confusing when the document scrolls down to hide
the folded lines.
  • Loading branch information...
1 parent 654f072 commit 00714db69c3ce8f8ba2d40be62c596045f1001d7 @ntrel ntrel committed
Showing with 14 additions and 1 deletion.
  1. +13 −0 src/editor.c
  2. +1 −1 src/sciwrappers.c
View
13 src/editor.c
@@ -444,7 +444,20 @@ void editor_toggle_fold(GeanyEditor *editor, gint line, gint modifiers)
g_return_if_fail(editor != NULL);
sci = editor->sci;
+ /* When collapsing a fold range whose starting line is offscreen,
+ * scroll the starting line to display at the top of the view.
+ * Otherwise it can be confusing when the document scrolls down to hide
+ * the folded lines. */
+ if ((sci_get_fold_level(sci, line) & SC_FOLDLEVELNUMBERMASK) > SC_FOLDLEVELBASE &&
+ !(sci_get_fold_level(sci, line) & SC_FOLDLEVELHEADERFLAG))
+ {
+ gint parent = sci_get_fold_parent(sci, line);
+ gint first = sci_get_first_visible_line(sci);
+ parent = SSM(sci, SCI_VISIBLEFROMDOCLINE, parent, 0);
+ if (first > parent)
+ SSM(sci, SCI_SETFIRSTVISIBLELINE, parent, 0);
+ }
sci_toggle_fold(sci, line);
/* extra toggling of child fold points
View
2 src/sciwrappers.c
@@ -682,7 +682,7 @@ gint sci_get_fold_parent(ScintillaObject *sci, gint start_line)
void sci_toggle_fold(ScintillaObject *sci, gint line)
{
- SSM(sci, SCI_TOGGLEFOLD, (uptr_t) line, 1);
+ SSM(sci, SCI_TOGGLEFOLD, (uptr_t) line, 0);
}

0 comments on commit 00714db

Please sign in to comment.
Something went wrong with that request. Please try again.