Fix vertical cursor motion across tall text or small images

'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)
This commit is contained in:
Eli Zaretskii 2021-05-13 16:12:10 +03:00
parent 1b919004f6
commit 1aaceec931
2 changed files with 46 additions and 2 deletions

View 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.

View 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;
}
/***********************************************************************
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");