Delete all overlays that belong to an editable-field
* 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.
This commit is contained in:
parent
0514619b2c
commit
d4220a17c4
2 changed files with 25 additions and 1 deletions
|
@ -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))))
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue