From d2f759a1d4c8a42db73ac62cb8317847a1b40249 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Fri, 4 Apr 2025 03:36:17 +0300 Subject: scroll caret __almost__ always automatically after key presses * The old heuristics - scroll if dot changes after key press - turned out to be too simplistic. They broke the clang-format macro (M#cf), which left the view at the top of the document since the entire document is temporarily erased. Other simplified examples of this bug would be: @^Um{[: HECcat$ ]:} Mm Or even: @^Um{[: H@X.aG.a ]:} Mm * Actually, the heuristics could be tricked even without deleting any significant amount of text from the buffer. The following test case replaces the previous character with a linefeed in a single key press: @^Um{-DI^J$} Mm If executed on the last visible line, dot wouldn't be scrolled into the view since it did not change. * At the same time, we'd like to keep the existing mouse scroll behavior from fnkeys.tes, which is allowed to scroll dot outside of the visible area. Therefore, dot is scrolled into view always, except after mouse events. You may have to call SCI_SCROLLCARET manually in the ^KMOUSE macro, which is arguably not always straight forward. * Some macros like M#cf may still leave the vertical scrolling position in unexpected positions. This could either be fixed by eradicating all remaining automatic scrolling from Scintilla or by explicitly restoring the vertical position from the macro (FIXME). * This was broken since the introduction of mouse support, so it wasn't in v2.3.0. --- src/interface-gtk/interface.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/interface-gtk/interface.c') diff --git a/src/interface-gtk/interface.c b/src/interface-gtk/interface.c index 7f58c45..25f4ccd 100644 --- a/src/interface-gtk/interface.c +++ b/src/interface-gtk/interface.c @@ -1383,7 +1383,6 @@ teco_interface_input_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) gdk_window_freeze_updates(top_window); const teco_view_t *last_view = teco_interface_current_view; - sptr_t last_pos = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0); teco_interrupted = FALSE; switch (event->type) { @@ -1409,8 +1408,11 @@ teco_interface_input_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) * Scintilla has been patched to avoid any automatic scrolling since that * has been benchmarked to be a very costly operation. * Instead we do it only once after every keypress. + * + * The only exception is mouse events, so you can scroll the view manually + * in the ^KMOUSE macro, allowing dot to be outside of the view. */ - if (last_pos != teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0)) + if (event->type == GDK_KEY_PRESS) teco_interface_ssm(SCI_SCROLLCARET, 0, 0); gdk_window_thaw_updates(top_window); -- cgit v1.2.3