mirror of
https://github.com/masscollaborationlabs/emacs.git
synced 2025-07-03 10:53:23 +00:00
Prevent button.el from clearing help-echo strings
In order to fix one of the issues discussed in bug#61413, i.e. 'buttonize' clobbering the help-echo property set by 'icon-string'. This is a reasonable interpretation of the button.el docstrings - "if HELP-ECHO, use that as the `help-echo' property"; conversely, if not HELP-ECHO, then do not do anything, preserving existing values for that property. * lisp/button.el (button--properties): Only add a help-echo property if HELP-ECHO is non-nil. Add an additional property for bookkeeping. (unbuttonize-region): Check for that bookkeeping property before clearing help-echo. * test/lisp/button-tests.el (button--preserve-help-echo): Validate these changes.
This commit is contained in:
parent
269d337f91
commit
f23ee93250
2 changed files with 49 additions and 11 deletions
|
@ -652,15 +652,19 @@ Also see `buttonize-region'."
|
|||
string))
|
||||
|
||||
(defun button--properties (callback data help-echo)
|
||||
(list 'font-lock-face 'button
|
||||
'mouse-face 'highlight
|
||||
'help-echo help-echo
|
||||
'button t
|
||||
'follow-link t
|
||||
'category t
|
||||
'button-data data
|
||||
'keymap button-map
|
||||
'action callback))
|
||||
(append
|
||||
(list 'font-lock-face 'button
|
||||
'mouse-face 'highlight
|
||||
'button t
|
||||
'follow-link t
|
||||
'category t
|
||||
'button-data data
|
||||
'keymap button-map
|
||||
'action callback)
|
||||
(and help-echo
|
||||
(list 'help-echo help-echo
|
||||
;; Record that button.el is responsible for this property.
|
||||
'help-echo-button t))))
|
||||
|
||||
(defun buttonize-region (start end callback &optional data help-echo)
|
||||
"Make the region between START and END into a button.
|
||||
|
@ -681,8 +685,14 @@ This removes both text-property and overlay based buttons."
|
|||
(when (overlay-get o 'button)
|
||||
(delete-overlay o)))
|
||||
(with-silent-modifications
|
||||
(remove-text-properties start end
|
||||
(button--properties nil nil nil))
|
||||
(remove-text-properties
|
||||
start end
|
||||
(append
|
||||
(button--properties nil nil nil)
|
||||
;; Only remove help-echo if it was added by button.el.
|
||||
(and (get-text-property start 'help-echo-button)
|
||||
(list 'help-echo nil
|
||||
'help-echo-button nil))))
|
||||
(add-face-text-property start end
|
||||
'button nil)))
|
||||
|
||||
|
|
|
@ -101,4 +101,32 @@
|
|||
(setq button (insert-button "overlay" 'help-echo help))
|
||||
(should (equal (button--help-echo button) "overlay: x")))))
|
||||
|
||||
(ert-deftest button--preserve-help-echo ()
|
||||
"Ensure buttonizing functions preserve existing `help-echo' properties."
|
||||
;; buttonize.
|
||||
(let* ((string (propertize "button text" 'help-echo "help text"))
|
||||
(button (buttonize string #'ignore)))
|
||||
(should (equal (get-text-property 0 'help-echo button)
|
||||
"help text")))
|
||||
;; buttonize-region.
|
||||
(with-temp-buffer
|
||||
(insert (propertize "button text" 'help-echo "help text"))
|
||||
(buttonize-region (point-min) (point) #'ignore)
|
||||
(should (equal (get-text-property (point-min) 'help-echo)
|
||||
"help text"))
|
||||
;; unbuttonize-region should not clear the property either.
|
||||
(unbuttonize-region (point-min) (point))
|
||||
(should (equal (get-text-property (point-min) 'help-echo)
|
||||
"help text")))
|
||||
;; unbuttonize-region should still clear properties applied with
|
||||
;; buttonize.
|
||||
(with-temp-buffer
|
||||
(insert "button text")
|
||||
(buttonize-region (point-min) (point) #'ignore nil "help text")
|
||||
(should (equal (get-text-property (point-min) 'help-echo)
|
||||
"help text"))
|
||||
(unbuttonize-region (point-min) (point))
|
||||
(should (equal (get-text-property (point-min) 'help-echo)
|
||||
nil))))
|
||||
|
||||
;;; button-tests.el ends here
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue