* 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)
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
: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.
(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