From 424d483baa98165ccd270704b7181a32ec6e7205 Mon Sep 17 00:00:00 2001 From: Mauro Aranda Date: Mon, 24 Feb 2025 19:39:43 -0300 Subject: [PATCH] Fix bad fontification of inactive widgets * lisp/wid-edit.el (widget-specify-inactive): When a widget is already inactive, still move the overlay to the desired positions. Improve docstring. (Bug#69941) * doc/misc/widget.texi (default): Document the need to call the :deactivate function when modifying an inactive widget. * test/lisp/wid-edit-tests.el (widget-test-modification-of-inactive-widget): New test (cherry picked from commit 363adcc69d322bdede1934b47e9dd1fbc3148ab9) --- doc/misc/widget.texi | 3 +++ lisp/wid-edit.el | 11 +++++++++-- test/lisp/wid-edit-tests.el | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/doc/misc/widget.texi b/doc/misc/widget.texi index 68d53a42025..f84e81bce77 100644 --- a/doc/misc/widget.texi +++ b/doc/misc/widget.texi @@ -1333,6 +1333,9 @@ modifications. Function that takes a widget and makes it inactive for user modifications. +If you modify a widget that is not active, you should make sure the +:deactivate function gets called again after the modifications. + @vindex action@r{ keyword} @item :action Function that takes a widget and optionally an event, and handles a diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el index 1ddfd0cc08e..b73dfd3bcbb 100644 --- a/lisp/wid-edit.el +++ b/lisp/wid-edit.el @@ -549,8 +549,15 @@ With CHECK-AFTER non-nil, considers also the content after point, if needed." :group 'widget-faces) (defun widget-specify-inactive (widget from to) - "Make WIDGET inactive for user modifications." - (unless (widget-get widget :inactive) + "Make WIDGET inactive for user modifications. + +If WIDGET is already inactive, moves the :inactive overlay to the positions +indicated by FROM and TO, either numbers or markers. + +If WIDGET is not inactive, creates an overlay that spans from FROM to TO, +and saves that overlay under the :inactive property for WIDGET." + (if (widget-get widget :inactive) + (move-overlay (widget-get widget :inactive) from to) (let ((overlay (make-overlay from to nil t nil))) (overlay-put overlay 'face 'widget-inactive) ;; This is disabled, as it makes the mouse cursor change shape. diff --git a/test/lisp/wid-edit-tests.el b/test/lisp/wid-edit-tests.el index e34aa64f8d1..755bd12201f 100644 --- a/test/lisp/wid-edit-tests.el +++ b/test/lisp/wid-edit-tests.el @@ -481,4 +481,18 @@ markers (and so on) as well." (should (= ofrom2 (widget-get group2 :from))) (should (= oto2 (widget-get group2 :to)))))) +(ert-deftest widget-test-modification-of-inactive-widget () + "Test that modifications to an inactive widget keep all of it inactive." + (with-temp-buffer + (let* ((radio (widget-create 'radio-button-choice + '(item "One") '(item "Two") '(item "Confirm"))) + (from (widget-get radio :from)) + (to (widget-get radio :to)) + (ov (progn (widget-apply radio :deactivate) + (widget-get radio :inactive)))) + (widget-value-set radio "") + (widget-apply radio :deactivate) + (should (= (overlay-start ov) from)) + (should (= (overlay-end ov) to))))) + ;;; wid-edit-tests.el ends here -- 2.39.5