From 6afd53b644c9b1fe0592892464c2d7fb37fa29e7 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Tue, 5 May 2026 05:21:28 -0500 Subject: fix: restore display state in the buffer setup ran in MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit org-drill--setup-display saved buffer-local state (mode-line, variable-pitch-mode) into global defvars and called setq-local on the current buffer. org-drill--restore-display read those globals and ran setq-local against whatever buffer happened to be current at restore time. If the user switched buffers mid-session, the restore wrote to the wrong buffer — leaving the original drill buffer's mode-line still hidden and trampling the destination buffer's mode-line with whatever was saved from elsewhere. Captured the buffer at setup in org-drill--saved-display-buffer. Restore now wraps mode-line and variable-pitch restoration in with-current-buffer against that saved buffer. Text-scale stays global (the underlying face attribute is process-wide). --- tests/test-org-drill-display-restore.el | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/test-org-drill-display-restore.el (limited to 'tests') diff --git a/tests/test-org-drill-display-restore.el b/tests/test-org-drill-display-restore.el new file mode 100644 index 0000000..90d1b0d --- /dev/null +++ b/tests/test-org-drill-display-restore.el @@ -0,0 +1,53 @@ +;;; test-org-drill-display-restore.el --- Regression for cross-buffer display restore -*- lexical-binding: t; -*- + +;;; Commentary: +;; The display setup / restore pair saved buffer-local state (mode-line, +;; variable-pitch-mode) to global defvars and restored via plain +;; `setq-local'. If the user switched buffers between setup and +;; restore, the restore wrote to the wrong buffer — leaving the +;; original drill buffer with its modeline still hidden, and trampling +;; the destination buffer's modeline. +;; +;; The fix tracks the buffer at setup and uses `with-current-buffer' +;; to restore in the original. + +;;; Code: + +(require 'ert) +(require 'cl-lib) +(require 'org) +(require 'org-drill) + +;;;; Cross-buffer modeline restore + +(ert-deftest test-display-restore-modeline-in-original-buffer-after-buffer-switch () + "Setup in buffer A, restore in buffer B — A's mode-line should be restored, +B's mode-line untouched." + (let ((buffer-a (generate-new-buffer "*org-drill-test-A*")) + (buffer-b (generate-new-buffer "*org-drill-test-B*")) + (org-drill-hide-modeline-during-session t) + (org-drill-text-size-during-session nil) + (org-drill-use-variable-pitch nil)) + (unwind-protect + (progn + (with-current-buffer buffer-a + (setq-local mode-line-format "A-original") + (org-drill--setup-display) + ;; A's modeline is now hidden (nil). + (should (null mode-line-format))) + (with-current-buffer buffer-b + (setq-local mode-line-format "B-original") + ;; Restore runs from buffer B (simulating a buffer switch + ;; mid-session). + (org-drill--restore-display)) + ;; After restore: A's modeline back to original, B's untouched. + (with-current-buffer buffer-a + (should (equal "A-original" mode-line-format))) + (with-current-buffer buffer-b + (should (equal "B-original" mode-line-format)))) + (kill-buffer buffer-a) + (kill-buffer buffer-b)))) + +(provide 'test-org-drill-display-restore) + +;;; test-org-drill-display-restore.el ends here -- cgit v1.2.3