@@ -1648,6 +1648,72 @@ cell, so the visual line width must equal the terminal column count."
16481648 (should-not scroll-bottom-called)
16491649 (should-not ghostel--force-next-redraw))))
16501650
1651+ (ert-deftest ghostel-test-scroll-forwards-mouse-tracking ()
1652+ " Scroll-up/down forward events when mouse tracking is active."
1653+ (let ((ghostel--term 'fake )
1654+ (ghostel--process 'fake )
1655+ (ghostel--copy-mode-active nil )
1656+ (ghostel--copy-mode-full-buffer nil )
1657+ (ghostel--force-next-redraw nil )
1658+ (mouse-event-args nil )
1659+ (scroll-called nil )
1660+ ; ; Fake wheel-up event at row 5, col 10
1661+ (fake-event `(wheel-up (,(selected-window ) 1 (10 . 5 ) 0 ))))
1662+ ; ; Mouse tracking active: ghostel--mouse-event returns non-nil
1663+ (cl-letf (((symbol-function 'ghostel--mouse-event )
1664+ (lambda (_term action button row col mods )
1665+ (setq mouse-event-args (list action button row col mods))
1666+ t ))
1667+ ((symbol-function 'ghostel--scroll )
1668+ (lambda (_term _delta ) (setq scroll-called t )))
1669+ ((symbol-function 'process-live-p ) (lambda (_p ) t )))
1670+ (ghostel--scroll-up fake-event)
1671+ (should mouse-event-args)
1672+ (should (equal 0 (nth 0 mouse-event-args))) ; action = press
1673+ (should (equal 4 (nth 1 mouse-event-args))) ; button 4 = scroll up
1674+ (should (equal 5 (nth 2 mouse-event-args))) ; row
1675+ (should (equal 10 (nth 3 mouse-event-args))) ; col
1676+ (should-not scroll-called))
1677+ ; ; Reset and test scroll-down with a wheel-down event
1678+ (setq mouse-event-args nil scroll-called nil )
1679+ (let ((fake-down-event `(wheel-down (,(selected-window ) 1 (10 . 5 ) 0 ))))
1680+ (cl-letf (((symbol-function 'ghostel--mouse-event )
1681+ (lambda (_term action button row col mods )
1682+ (setq mouse-event-args (list action button row col mods))
1683+ t ))
1684+ ((symbol-function 'ghostel--scroll )
1685+ (lambda (_term _delta ) (setq scroll-called t )))
1686+ ((symbol-function 'process-live-p ) (lambda (_p ) t )))
1687+ (ghostel--scroll-down fake-down-event)
1688+ (should mouse-event-args)
1689+ (should (equal 5 (nth 1 mouse-event-args))) ; button 5 = scroll down
1690+ (should-not scroll-called)))))
1691+
1692+ (ert-deftest ghostel-test-scroll-fallback-no-mouse-tracking ()
1693+ " Scroll-up/down fall back to viewport scroll when mouse tracking is off."
1694+ (let ((ghostel--term 'fake )
1695+ (ghostel--process 'fake )
1696+ (ghostel--copy-mode-active nil )
1697+ (ghostel--copy-mode-full-buffer nil )
1698+ (ghostel--force-next-redraw nil )
1699+ (scroll-delta nil )
1700+ (fake-up-event `(wheel-up (,(selected-window ) 1 (10 . 5 ) 0 )))
1701+ (fake-down-event `(wheel-down (,(selected-window ) 1 (10 . 5 ) 0 ))))
1702+ (cl-letf (((symbol-function 'ghostel--mouse-event )
1703+ (lambda (_term _action _button _row _col _mods ) nil ))
1704+ ((symbol-function 'ghostel--scroll )
1705+ (lambda (_term delta ) (setq scroll-delta delta)))
1706+ ((symbol-function 'ghostel--invalidate ) #'ignore )
1707+ ((symbol-function 'process-live-p ) (lambda (_p ) t )))
1708+ (ghostel--scroll-up fake-up-event)
1709+ (should (equal -3 scroll-delta))
1710+ (should ghostel--force-next-redraw)
1711+ ; ; Reset and test scroll-down fallback
1712+ (setq scroll-delta nil ghostel--force-next-redraw nil )
1713+ (ghostel--scroll-down fake-down-event)
1714+ (should (equal 3 scroll-delta))
1715+ (should ghostel--force-next-redraw))))
1716+
16511717(ert-deftest ghostel-test-control-key-bindings ()
16521718 " All non-exception C-<letter> keys should be bound in ghostel-mode-map."
16531719 (dolist (c (number-sequence ?a ?z ))
@@ -1868,6 +1934,8 @@ cell, so the visual line width must equal the terminal column count."
18681934 ghostel-test-scroll-on-input-self-insert
18691935 ghostel-test-scroll-on-input-send-event
18701936 ghostel-test-scroll-on-input-disabled
1937+ ghostel-test-scroll-forwards-mouse-tracking
1938+ ghostel-test-scroll-fallback-no-mouse-tracking
18711939 ghostel-test-control-key-bindings
18721940 ghostel-test-meta-key-bindings
18731941 ghostel-test-copy-mode-recenter
0 commit comments