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
This commit is contained in:
Mauro Aranda 2025-02-24 19:39:43 -03:00
parent 60232a30e3
commit 363adcc69d
3 changed files with 26 additions and 2 deletions

View 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

View 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.

View 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