diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-05 05:21:28 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-05 05:21:28 -0500 |
| commit | 6afd53b644c9b1fe0592892464c2d7fb37fa29e7 (patch) | |
| tree | 1769d6b60937e71c395ddef67e9e5bfcd58f8a97 /tests | |
| parent | 7f7564612628d31718c2fc1e4471ab7fa29ef3c1 (diff) | |
| download | org-drill-6afd53b644c9b1fe0592892464c2d7fb37fa29e7.tar.gz org-drill-6afd53b644c9b1fe0592892464c2d7fb37fa29e7.zip | |
fix: restore display state in the buffer setup ran in
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).
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-org-drill-display-restore.el | 53 |
1 files changed, 53 insertions, 0 deletions
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 |
