From 52c031775dca66d308cc341271900258f36b5895 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 18 Jul 2026 15:38:49 -0500 Subject: fix(music): show the cursor on the row number and open the dock taller With point pinned at the row start, redisplay drew the cursor after the number's before-string, on the album-art thumbnail, where a block cursor is invisible. A cursor property on the number string makes redisplay draw it on the number. The dock also kept reopening too short: its height memory remembered whatever size the window had at toggle-off, including squeezes from window churn. The squeezed fraction then overrode the default on every later open. The default rises to a third of the frame, and the toggle discards captured heights below it (a deliberate enlargement still sticks for the session). --- modules/music-config.el | 20 +++++++++++++--- tests/test-music-config--playlist-dock.el | 39 +++++++++++++++++++++++++++++++ tests/test-music-config--renumber-rows.el | 10 ++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/modules/music-config.el b/modules/music-config.el index 02df2467..5f35d2cc 100644 --- a/modules/music-config.el +++ b/modules/music-config.el @@ -393,9 +393,14 @@ debounce timer can outlive the playlist buffer." (let ((ov (make-overlay (line-beginning-position) (1+ (line-beginning-position))))) (overlay-put ov 'cj-music-row-number t) + ;; The cursor property makes redisplay draw the cursor ON + ;; the number when point sits at the row start; without it + ;; the cursor lands after the before-string, on the + ;; album-art thumbnail, where it's invisible. (overlay-put ov 'before-string (propertize (format "%3d " n) - 'face 'cj/music-keyhint-face)))) + 'face 'cj/music-keyhint-face + 'cursor t)))) (forward-line 1)))))))) (defun cj/music--schedule-renumber (&rest _) @@ -893,11 +898,13 @@ Intended for use on `emms-player-finished-hook'." ) -(defvar cj/music-playlist-window-height 0.3 +(defvar cj/music-playlist-window-height 0.33 "Default fraction of frame height for the F10 music playlist side window. +A third of the frame, so a playlist of real length shows enough rows. Used when the playlist hasn't been resized and toggled off this session; after that, the toggled-off height is remembered in -`cj/--music-playlist-height'.") +`cj/--music-playlist-height' -- but only when it's at least this default +\(see the discard in `cj/music-playlist-toggle').") (defvar cj/--music-playlist-height nil "Last height fraction the playlist was toggled off at. @@ -920,6 +927,13 @@ resized and toggled off this session, it reopens at that remembered height." (if win (progn (cj/side-window-capture-size win 'bottom 'cj/--music-playlist-height) + ;; Remember enlargements only. Window churn (another side window + ;; opening) squeezes the dock, and remembering the squeeze reopens + ;; it too short on every later toggle. A deliberate shrink is the + ;; rare case; losing it costs one resize. + (when (and (numberp cj/--music-playlist-height) + (< cj/--music-playlist-height cj/music-playlist-window-height)) + (setq cj/--music-playlist-height nil)) (delete-window win) (message "Playlist window closed")) (progn diff --git a/tests/test-music-config--playlist-dock.el b/tests/test-music-config--playlist-dock.el index 69d24cc3..501ff272 100644 --- a/tests/test-music-config--playlist-dock.el +++ b/tests/test-music-config--playlist-dock.el @@ -70,5 +70,44 @@ silently does nothing." (should-not (boundp 'cj/--music-playlist-width)) (should-not (fboundp 'cj/--music-playlist-side))) +(ert-deftest test-music-config-playlist-default-height-is-a-third () + "Normal: the dock opens at a third of the frame height by default." + (should (= cj/music-playlist-window-height 0.33))) + +(ert-deftest test-music-config-playlist-toggle-off-discards-shrunk-height () + "Error: a captured height below the default is discarded. Window churn +squeezes the dock, and remembering the squeeze reopens it too short on +every later toggle." + (let ((buffer (generate-new-buffer " *test-playlist-shrink*")) + (cj/--music-playlist-height nil)) + (unwind-protect + (save-window-excursion + (set-window-buffer (selected-window) buffer) + (let ((cj/music-playlist-buffer-name (buffer-name buffer))) + (cl-letf (((symbol-function 'cj/side-window-capture-size) + (lambda (_w _side var) (set var 0.2))) + ((symbol-function 'delete-window) #'ignore) + ((symbol-function 'message) #'ignore)) + (cj/music-playlist-toggle))) + (should (null cj/--music-playlist-height))) + (kill-buffer buffer)))) + +(ert-deftest test-music-config-playlist-toggle-off-keeps-enlarged-height () + "Normal: a captured height at or above the default is remembered, so a +deliberate enlargement sticks for the session." + (let ((buffer (generate-new-buffer " *test-playlist-grow*")) + (cj/--music-playlist-height nil)) + (unwind-protect + (save-window-excursion + (set-window-buffer (selected-window) buffer) + (let ((cj/music-playlist-buffer-name (buffer-name buffer))) + (cl-letf (((symbol-function 'cj/side-window-capture-size) + (lambda (_w _side var) (set var 0.5))) + ((symbol-function 'delete-window) #'ignore) + ((symbol-function 'message) #'ignore)) + (cj/music-playlist-toggle))) + (should (= 0.5 cj/--music-playlist-height))) + (kill-buffer buffer)))) + (provide 'test-music-config--playlist-dock) ;;; test-music-config--playlist-dock.el ends here diff --git a/tests/test-music-config--renumber-rows.el b/tests/test-music-config--renumber-rows.el index 8abe1704..449f6d2e 100644 --- a/tests/test-music-config--renumber-rows.el +++ b/tests/test-music-config--renumber-rows.el @@ -47,6 +47,16 @@ (cj/music--renumber-rows (current-buffer)) (should (= 2 (length (test-music-renumber--numbers (current-buffer))))))) +(ert-deftest test-music-renumber-rows-number-carries-cursor-property () + "Normal: the number string carries a cursor property. Point is pinned at +the row start, and without the property redisplay draws the cursor after +the before-string -- on the album-art thumbnail, where it's invisible." + (with-temp-buffer + (insert "track one\n") + (cj/music--renumber-rows (current-buffer)) + (let ((s (car (test-music-renumber--numbers (current-buffer))))) + (should (get-text-property 0 'cursor s))))) + ;;; Boundary Cases (ert-deftest test-music-renumber-rows-skips-blank-lines () -- cgit v1.2.3