]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix bad fontification of inactive widgets
authorMauro Aranda <maurooaranda@gmail.com>
Mon, 24 Feb 2025 22:39:43 +0000 (19:39 -0300)
committerEshel Yaron <me@eshelyaron.com>
Wed, 26 Feb 2025 09:36:23 +0000 (10:36 +0100)
* 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
lisp/wid-edit.el
test/lisp/wid-edit-tests.el

index 68d53a42025c6031f65f0501425760b143bb075f..f84e81bce77eebbc466dd39df4fa93e4a488c232 100644 (file)
@@ -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
index 1ddfd0cc08e3a05381f86fe57aa25e048a475eaa..b73dfd3bcbb3f3a9bd7143308ac3a88e5383e7b3 100644 (file)
@@ -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.
index e34aa64f8d134e155c7b9d791e61346af1e62ef5..755bd12201f58576e7d92e04c8a61fa1d1ac3cf7 100644 (file)
@@ -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