]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix vertical cursor motion across tall text or small images
authorEli Zaretskii <eliz@gnu.org>
Thu, 13 May 2021 13:12:10 +0000 (16:12 +0300)
committerEli Zaretskii <eliz@gnu.org>
Thu, 13 May 2021 13:12:10 +0000 (16:12 +0300)
'line-move-partial' should in general leave it to the display
engine to scroll or recenter the window due to vertical motion of
the cursor.  The only purpose of this function is to produce
vscroll suitable for scrolling across large (relatively to the
window's height) images, where moving by display lines is not
appropriate.

* src/xdisp.c (Fdisplay__line_is_continued_p): New primitive.

* lisp/simple.el (line-move-partial): Call
'display--line-is-continued-p' to decide whether to leave it to
redisplay to scroll the window as appropriate.  (Bug#48170)

lisp/simple.el
src/xdisp.c

index 35bb472be03d4ec84ee59f04e6c6f7d522246ea4..0255f69e42710c448f1feff303ab6d741e17d4f4 100644 (file)
@@ -6935,11 +6935,13 @@ The value is a floating-point number."
               (or (null rbot) (= rbot 0)))
          nil)
         ;; If cursor is not in the bottom scroll margin, and the
-        ;; current line is not too tall, move forward.
+        ;; current line is not too tall, or if there's a continuation
+        ;; line below this one, move forward.
         ((and (or (null this-height) (<= this-height winh))
               vpos
               (> vpos 0)
-              (< py last-line))
+              (or (< py last-line)
+                   (display--line-is-continued-p)))
          nil)
         ;; When already vscrolled, we vscroll some more if we can,
         ;; or clear vscroll and move forward at end of tall image.
index 23b4ba5c39c58ea8ec8f1defe28b7b9964d406e4..4841a0af6f3ccc1e3fabfa785e5d940661b8fc00 100644 (file)
@@ -10838,6 +10838,47 @@ include the height of both, if present, in the return value.  */)
 
   return Fcons (make_fixnum (x - start_x), make_fixnum (y));
 }
+
+DEFUN ("display--line-is-continued-p", Fdisplay__line_is_continued_p,
+       Sdisplay__line_is_continued_p, 0, 0, 0,
+       doc: /* Return non-nil if the current screen line is continued on display.  */)
+  (void)
+{
+  struct buffer *oldb = current_buffer;
+  struct window *w = XWINDOW (selected_window);
+  enum move_it_result rc = MOVE_POS_MATCH_OR_ZV;
+
+  set_buffer_internal_1 (XBUFFER (w->contents));
+
+  if (PT < ZV)
+    {
+      struct text_pos startpos;
+      struct it it;
+      void *itdata;
+      /* Use a marker, since vertical-motion enters redisplay, which can
+        trigger fontifications, which in turn could modify buffer text.  */
+      Lisp_Object opoint = Fpoint_marker ();
+
+      /* Make sure to start from the beginning of the current screen
+        line, so that move_it_in_display_line_to counts pixels correctly.  */
+      Fvertical_motion (make_fixnum (0), selected_window, Qnil);
+      SET_TEXT_POS (startpos, PT, PT_BYTE);
+      itdata = bidi_shelve_cache ();
+      start_display (&it, w, startpos);
+      /* If lines are truncated, no line is continued.  */
+      if (it.line_wrap != TRUNCATE)
+       {
+         it.glyph_row = NULL;
+         rc = move_it_in_display_line_to (&it, ZV, -1, MOVE_TO_POS);
+       }
+      SET_PT_BOTH (marker_position (opoint), marker_byte_position (opoint));
+      bidi_unshelve_cache (itdata, false);
+    }
+  set_buffer_internal_1 (oldb);
+
+  return rc == MOVE_LINE_CONTINUED ? Qt : Qnil;
+}
+
 \f
 /***********************************************************************
                               Messages
@@ -34739,6 +34780,7 @@ be let-bound around code that needs to disable messages temporarily. */);
   defsubr (&Swindow_text_pixel_size);
   defsubr (&Smove_point_visually);
   defsubr (&Sbidi_find_overridden_directionality);
+  defsubr (&Sdisplay__line_is_continued_p);
 
   DEFSYM (Qmenu_bar_update_hook, "menu-bar-update-hook");
   DEFSYM (Qoverriding_terminal_local_map, "overriding-terminal-local-map");