(let* ((edges (window-edges nil t nil t))
(max-y (- (nth 3 edges)
(nth 1 edges)))
- (usable-height max-y))
- (when-let* ((posn (posn-at-point))
- (current-y (+ (cdr (posn-x-y posn))
- (line-pixel-height))))
- (while (and (<= (- max-y current-y) delta)
- (<= (cdr (posn-object-width-height posn))
- usable-height))
- (vertical-motion -1)
- (setq current-y (- current-y (line-pixel-height))))
- (when (and (>= (cdr (posn-object-width-height posn))
- usable-height)
- (let ((prev-line-height (save-excursion
- (vertical-motion -1)
- (line-pixel-height))))
- (<= 0 (- (cdr (posn-x-y posn)) prev-line-height))))
- (vertical-motion -1)))
+ (usable-height max-y)
+ (posn (posn-at-x-y 0 (+ (window-tab-line-height)
+ (window-header-line-height)
+ (- max-y delta))))
+ (point (posn-point posn))
+ (up-point (save-excursion
+ (goto-char point)
+ (vertical-motion -1)
+ (point))))
+ (when (> (point) up-point)
+ (when (let ((pos-visible (pos-visible-in-window-p up-point nil t)))
+ (or (eq (length pos-visible) 2)
+ (when-let* ((posn (posn-at-point up-point))
+ (edges (window-edges nil t))
+ (usable-height (- (nth 3 edges)
+ (nth 1 edges))))
+ (> (cdr (posn-object-width-height posn))
+ usable-height))))
+ (goto-char up-point)))
(let ((current-vscroll (window-vscroll nil t)))
(if (<= delta current-vscroll)
(set-window-vscroll nil (- current-vscroll delta) t)