diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-02-02 16:09:08 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-02-16 02:20:39 +0300 |
commit | 980dcdaa138a42830af4e2533b7e970d7f5fa3cf (patch) | |
tree | a3848f050b86913b4652b44c146077664eeb9028 | |
parent | b87c56799ab6f6d651e1dc6c712a625545a4ad5f (diff) | |
download | sciteco-980dcdaa138a42830af4e2533b7e970d7f5fa3cf.tar.gz |
only scroll the caret if dot changes
* Fixes scrolling with default ^KMOUSE macro from fnkeys.tes which adjusts
the scroll position without changing dot.
The unconditional SCI_SCROLLCARET would effectively prevent scrolling to any position
that does not contain dot.
-rw-r--r-- | src/interface-curses/interface.c | 19 | ||||
-rw-r--r-- | src/interface-gtk/interface.c | 24 |
2 files changed, 28 insertions, 15 deletions
diff --git a/src/interface-curses/interface.c b/src/interface-curses/interface.c index fe2b1bb..9480822 100644 --- a/src/interface-curses/interface.c +++ b/src/interface-curses/interface.c @@ -1573,13 +1573,6 @@ static void teco_interface_refresh(void) { /* - * 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. - */ - teco_interface_ssm(SCI_SCROLLCARET, 0, 0); - - /* * Info window is updated very often which is very * costly, especially when using PDC_set_title(), * so we redraw it here, where the overhead does @@ -1723,6 +1716,9 @@ teco_interface_event_loop_iter(void) ? teco_interface_blocking_getch() : GPOINTER_TO_INT(g_queue_pop_head(teco_interface.input_queue)); + const teco_view_t *last_view = teco_interface_current_view; + sptr_t last_pos = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0); + switch (key) { case ERR: /* shouldn't really happen */ @@ -1842,6 +1838,14 @@ teco_interface_event_loop_iter(void) } } + /* + * 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. + */ + if (teco_interface_current_view != last_view || + last_pos != teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0)) + teco_interface_ssm(SCI_SCROLLCARET, 0, 0); teco_interface_refresh(); } @@ -1857,6 +1861,7 @@ teco_interface_event_loop(GError **error) static const teco_cmdline_t empty_cmdline; // FIXME teco_interface_cmdline_update(&empty_cmdline); teco_interface_msg_clear(); + teco_interface_ssm(SCI_SCROLLCARET, 0, 0); teco_interface_refresh(); #ifdef EMCURSES diff --git a/src/interface-gtk/interface.c b/src/interface-gtk/interface.c index 4619b75..ed9271b 100644 --- a/src/interface-gtk/interface.c +++ b/src/interface-gtk/interface.c @@ -924,13 +924,6 @@ teco_interface_refresh(gboolean current_view_changed) teco_interface.current_view_widget); gtk_widget_show(teco_interface.current_view_widget); } - - /* - * 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. - */ - teco_interface_ssm(SCI_SCROLLCARET, 0, 0); } static void @@ -1342,10 +1335,14 @@ static void teco_interface_size_allocate_cb(GtkWidget *widget, GdkRectangle *allocation, gpointer user_data) { + static gboolean scrolled = FALSE; + /* * This especially ensures that the caret is visible after startup. */ - teco_interface_ssm(SCI_SCROLLCARET, 0, 0); + if (G_UNLIKELY(!scrolled)) + teco_interface_ssm(SCI_SCROLLCARET, 0, 0); + scrolled = TRUE; } static gboolean @@ -1410,7 +1407,9 @@ teco_interface_input_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) * the Curses UI. */ 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) { @@ -1432,6 +1431,15 @@ teco_interface_input_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) teco_interrupted = FALSE; teco_interface_refresh(teco_interface_current_view != last_view); + /* + * 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. + */ + if (teco_interface_current_view != last_view || + last_pos != teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0)) + teco_interface_ssm(SCI_SCROLLCARET, 0, 0); + gdk_window_thaw_updates(top_window); if (g_error_matches(error, TECO_ERROR, TECO_ERROR_QUIT)) { |