Fix disruption of windows' display by shr.el

* src/window.c (struct saved_window): New member 'vscroll'.
(Fset_window_configuration, save_window_save): Save and restore
the window's vscroll value.

* lisp/net/shr.el (shr-insert-document): Restore the original
window's hscroll, in case we are rendering in a window other than
where the document will be eventually displayed.  This avoids
resetting hscroll of windows we use temporarily for shr's
rendering job.  (Bug#56008)
This commit is contained in:
Eli Zaretskii 2022-06-16 19:53:45 +03:00
parent 28218092a6
commit 5eb9383ccc
2 changed files with 12 additions and 5 deletions

View file

@ -361,6 +361,7 @@ DOM should be a parse tree as generated by
(shr--window-width)))
(max-specpdl-size max-specpdl-size)
(shr--link-targets nil)
(hscroll (window-hscroll))
;; `bidi-display-reordering' is supposed to be only used for
;; debugging purposes, but Shr's naïve filling algorithm
;; cannot cope with the complexity of RTL text in an LTR
@ -380,11 +381,14 @@ DOM should be a parse tree as generated by
;; below will misbehave, because it silently assumes that it
;; starts with a non-hscrolled window (vertical-motion will move
;; to a wrong place otherwise).
(set-window-hscroll nil 0)
(shr-descend dom)
(shr-fill-lines start (point))
(shr--remove-blank-lines-at-the-end start (point))
(shr--set-target-ids shr--link-targets)
(unwind-protect
(progn
(set-window-hscroll nil 0)
(shr-descend dom)
(shr-fill-lines start (point))
(shr--remove-blank-lines-at-the-end start (point))
(shr--set-target-ids shr--link-targets))
(set-window-hscroll nil hscroll))
(when shr-warning
(message "%s" shr-warning))))

View file

@ -6901,6 +6901,7 @@ struct saved_window
Lisp_Object left_col, top_line, total_cols, total_lines;
Lisp_Object normal_cols, normal_lines;
Lisp_Object hscroll, min_hscroll, hscroll_whole, suspend_auto_hscroll;
Lisp_Object vscroll;
Lisp_Object parent, prev;
Lisp_Object start_at_line_beg;
Lisp_Object display_table;
@ -7128,6 +7129,7 @@ the return value is nil. Otherwise the value is t. */)
w->suspend_auto_hscroll = !NILP (p->suspend_auto_hscroll);
w->min_hscroll = XFIXNAT (p->min_hscroll);
w->hscroll_whole = XFIXNAT (p->hscroll_whole);
w->vscroll = -XFIXNAT (p->vscroll);
wset_display_table (w, p->display_table);
w->left_margin_cols = XFIXNUM (p->left_margin_cols);
w->right_margin_cols = XFIXNUM (p->right_margin_cols);
@ -7462,6 +7464,7 @@ save_window_save (Lisp_Object window, struct Lisp_Vector *vector, ptrdiff_t i)
p->suspend_auto_hscroll = w->suspend_auto_hscroll ? Qt : Qnil;
XSETFASTINT (p->min_hscroll, w->min_hscroll);
XSETFASTINT (p->hscroll_whole, w->hscroll_whole);
XSETFASTINT (p->vscroll, -w->vscroll);
p->display_table = w->display_table;
p->left_margin_cols = make_fixnum (w->left_margin_cols);
p->right_margin_cols = make_fixnum (w->right_margin_cols);