aboutsummaryrefslogtreecommitdiff
path: root/tests/test-music-config--renumber-rows.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-18 16:27:08 -0500
committerCraig Jennings <c@cjennings.net>2026-07-18 16:27:08 -0500
commit4e63f665bf153203377f58161aa782a25ffd5e9f (patch)
treef5528815bc22fa1ae969414bf9b9116608e45227 /tests/test-music-config--renumber-rows.el
parentd2742cead6539aa343fe2564fd8753ce2671345f (diff)
downloaddotemacs-4e63f665bf153203377f58161aa782a25ffd5e9f.tar.gz
dotemacs-4e63f665bf153203377f58161aa782a25ffd5e9f.zip
feat(music): freeze the playlist header while the track list scrolls
The header block (playlist name, now-playing hero, key legend) is an overlay string anchored at buffer position 1, so scrolling the list carried it off the top, key legend included. A handler on the buffer-local window-scroll-functions re-anchors the overlay at the window's display start on every scroll, so the block stays pinned at the top of the window. The header refresh timer now anchors at the same position instead of the buffer top, so the once-a-second update can't yank a scrolled header back.
Diffstat (limited to 'tests/test-music-config--renumber-rows.el')
-rw-r--r--tests/test-music-config--renumber-rows.el50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/test-music-config--renumber-rows.el b/tests/test-music-config--renumber-rows.el
index a5304606..d5bc5141 100644
--- a/tests/test-music-config--renumber-rows.el
+++ b/tests/test-music-config--renumber-rows.el
@@ -165,6 +165,56 @@ selected -- the dock is glanced at from other windows constantly."
(should (buffer-local-value 'hl-line-sticky-flag created)))
(when (buffer-live-p created) (kill-buffer created))))))
+;;; Sticky header
+
+(ert-deftest test-music-stick-header-moves-overlay-to-window-start ()
+ "Normal: a scroll re-anchors the header overlay at the new window start,
+so the header block stays at the top of the window while the list scrolls."
+ (with-temp-buffer
+ (insert "track one\ntrack two\ntrack three\ntrack four\n")
+ (setq cj/music--header-overlay (make-overlay (point-min) (point-min)))
+ (save-window-excursion
+ (set-window-buffer (selected-window) (current-buffer))
+ (let ((start (save-excursion (goto-char (point-min)) (forward-line 2) (point))))
+ (cj/music--stick-header (selected-window) start)
+ (should (= (overlay-start cj/music--header-overlay) start))
+ ;; Converges: the same start again is a no-op, not a loop.
+ (cj/music--stick-header (selected-window) start)
+ (should (= (overlay-start cj/music--header-overlay) start))))))
+
+(ert-deftest test-music-stick-header-no-overlay-noop ()
+ "Boundary: no header overlay yet -- the scroll handler is a silent no-op."
+ (with-temp-buffer
+ (insert "track one\n")
+ (setq cj/music--header-overlay nil)
+ (save-window-excursion
+ (set-window-buffer (selected-window) (current-buffer))
+ (should-not (cj/music--stick-header (selected-window) (point-min))))))
+
+(ert-deftest test-music-header-anchor-position-displayed-vs-not ()
+ "Normal: the header anchors at the displaying window's start; an
+undisplayed buffer anchors at the top."
+ (with-temp-buffer
+ (insert "track one\ntrack two\ntrack three\ntrack four\n")
+ (save-window-excursion
+ (set-window-buffer (selected-window) (current-buffer))
+ (let ((start (save-excursion (goto-char (point-min)) (forward-line 2) (point))))
+ (set-window-start (selected-window) start)
+ (should (= (cj/music--header-anchor-position) start))))
+ ;; Not displayed after the excursion restores the old config.
+ (should (= (cj/music--header-anchor-position) (point-min)))))
+
+(ert-deftest test-music-ensure-playlist-buffer-wires-scroll-hook ()
+ "Normal: the playlist buffer re-sticks its header on every window scroll."
+ (let (created)
+ (cl-letf (((symbol-function 'emms-playlist-mode) #'ignore))
+ (unwind-protect
+ (progn
+ (setq created (cj/music--ensure-playlist-buffer))
+ (with-current-buffer created
+ (should (member #'cj/music--stick-header window-scroll-functions))))
+ (when (buffer-live-p created) (kill-buffer created))))))
+
;;; Hook wiring
(ert-deftest test-music-renumber-ensure-playlist-buffer-wires-hook ()