]> git.eshelyaron.com Git - emacs.git/commitdiff
Delete all overlays that belong to an editable-field
authorMauro Aranda <maurooaranda@gmail.com>
Sat, 18 Jan 2025 11:25:40 +0000 (08:25 -0300)
committerEshel Yaron <me@eshelyaron.com>
Sat, 25 Jan 2025 17:49:06 +0000 (18:49 +0100)
* lisp/wid-edit.el (widget-specify-field): Store the end overlay
that we sometimes create for an editable-field widget.
(widget-field-value-delete): Make sure we delete all overlays
that belong to the widget.  (Bug#75646)

* test/lisp/wid-edit-tests.el (widget-test-delete-field-overlays): New
test.

(cherry picked from commit d4220a17c4ecf4639a276352149218077c1d6315)

lisp/wid-edit.el
test/lisp/wid-edit-tests.el

index 7a84d6fe2ffc67cd054d7291bec623930cfbbffa..70dc30ae55944739aaf88c296e6c458e652c71f6 100644 (file)
@@ -416,6 +416,9 @@ the :notify function can't know the new value.")
       ;; character (so we don't do this for the character widget),
       ;; or if the size of the editable field isn't specified.
       (let ((overlay (make-overlay (1- to) to nil t nil)))
+        ;; Save it so that we can easily delete it in
+        ;; `widget-field-value-delete'.  (Bug#75646)
+        (widget-put widget :field-end-overlay overlay)
        (overlay-put overlay 'field 'boundary)
         ;; We need the real field for tabbing.
        (overlay-put overlay 'real-field widget)
@@ -2223,11 +2226,16 @@ the earlier input."
     (set-marker-insertion-type (car overlay) t)))
 
 (defun widget-field-value-delete (widget)
-  "Remove the widget from the list of active editing fields."
+  "Remove the field WIDGET from the list of active editing fields.
+
+Delete its overlays as well."
   (setq widget-field-list (delq widget widget-field-list))
   (setq widget-field-new (delq widget widget-field-new))
   ;; These are nil if the :format string doesn't contain `%v'.
   (let ((overlay (widget-get widget :field-overlay)))
+    (when (overlayp overlay)
+      (delete-overlay overlay)))
+  (let ((overlay (widget-get widget :field-end-overlay)))
     (when (overlayp overlay)
       (delete-overlay overlay))))
 
index 6f3c87a809fcc0ca6cd4564dffca12a6189b9184..c18e6d14c4ce7cd95f1c72cc5bd24a612b9ad1e4 100644 (file)
@@ -414,4 +414,20 @@ return nil, even with a non-nil bubblep argument."
       (delete-char 1)
       (should (string= (widget-value w) "")))))
 
+(ert-deftest widget-test-delete-field-overlays ()
+  "Test that we delete all the field's overlays when deleting it."
+  (with-temp-buffer
+    (let ((field (widget-create 'editable-field
+                                :format "%t: %v "
+                                :tag "Delete me"))
+          field-overlay field-end-overlay)
+      (widget-insert "\n")
+      (widget-setup)
+      (widget-backward 1)
+      (setq field-overlay (widget-get field :field-overlay))
+      (setq field-end-overlay (car (overlays-at (point))))
+      (widget-delete field)
+      (should-not (overlay-buffer field-overlay))
+      (should-not (overlay-buffer field-end-overlay)))))
+
 ;;; wid-edit-tests.el ends here