Fix tp-name property being incorrectly set for layer names in string form
When calling (tp-set str 'layer-name), the layer name symbol was wrapped in a list by tp--parse-args. tp--resolve-props then incorrectly treated this single-element list as a plist and generated an anonymous tp-anon-X name instead of using the actual layer name. The fix adds detection in tp--resolve-props for single-element lists containing a defined layer/group name symbol, and correctly resolves them by recursing with just the symbol. Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
This commit is contained in:
parent
ab460db3d0
commit
7b4c2a0e63
15
tp-tests.el
15
tp-tests.el
@ -2070,6 +2070,21 @@ Returns list of (START END VALUE) intervals."
|
|||||||
;; tp-name should be preserved for reactive text property support
|
;; tp-name should be preserved for reactive text property support
|
||||||
(should (eq (get-text-property 0 'tp-name str) 'my-style))))
|
(should (eq (get-text-property 0 'tp-name str) 'my-style))))
|
||||||
|
|
||||||
|
(ert-deftest tp-test-set-entire-string-with-layer-name ()
|
||||||
|
"Test tp-set with layer name on entire string (string form).
|
||||||
|
This tests the fix for the bug where (tp-set str 'layer-name) would
|
||||||
|
incorrectly generate an anonymous tp-name instead of using the layer name."
|
||||||
|
(tp-test-with-temp-buffer
|
||||||
|
;; Define a layer with reactive variables
|
||||||
|
(tp-define-layer my-entire-string-layer
|
||||||
|
:props (face (:background $my-entire-string-color))
|
||||||
|
:data ((my-entire-string-color . "blue")))
|
||||||
|
(let ((str (tp-set " " 'my-entire-string-layer)))
|
||||||
|
;; tp-name should be the defined layer name, not an anonymous tp-anon-X
|
||||||
|
(should (eq (get-text-property 0 'tp-name str) 'my-entire-string-layer))
|
||||||
|
;; face should be correctly set
|
||||||
|
(should (equal (plist-get (get-text-property 0 'face str) :background) "blue")))))
|
||||||
|
|
||||||
(ert-deftest tp-test-reset-with-layer-name ()
|
(ert-deftest tp-test-reset-with-layer-name ()
|
||||||
"Test tp-reset accepts a layer name defined by define-tp."
|
"Test tp-reset accepts a layer name defined by define-tp."
|
||||||
(tp-test-with-temp-buffer
|
(tp-test-with-temp-buffer
|
||||||
|
|||||||
14
tp.el
14
tp.el
@ -2337,6 +2337,7 @@ Appends 'tp-name property to identify the layer."
|
|||||||
"Resolve PROPS to a property list with layer metadata.
|
"Resolve PROPS to a property list with layer metadata.
|
||||||
PROPS can be:
|
PROPS can be:
|
||||||
- A symbol (layer name from `tp-layer-alist' or group name from `tp-layer-groups')
|
- A symbol (layer name from `tp-layer-alist' or group name from `tp-layer-groups')
|
||||||
|
- A single-element list containing a layer/group symbol (from string form of tp-set)
|
||||||
- A plist (handles anonymous layers with reactive variables)
|
- A plist (handles anonymous layers with reactive variables)
|
||||||
|
|
||||||
If PROPS is a symbol:
|
If PROPS is a symbol:
|
||||||
@ -2356,6 +2357,17 @@ For group names, includes `tp-layers' property with the full layer stack."
|
|||||||
(cond
|
(cond
|
||||||
;; Already a plist - check for reactive variables and add tp-name
|
;; Already a plist - check for reactive variables and add tp-name
|
||||||
((listp props)
|
((listp props)
|
||||||
|
;; Handle single-element list containing a layer/group name symbol.
|
||||||
|
;; This can happen when tp-set is called with string form: (tp-set str 'layer-name)
|
||||||
|
;; which produces props = (layer-name) in tp--parse-args.
|
||||||
|
(let ((first-elem (car-safe props)))
|
||||||
|
(if (and (= (length props) 1)
|
||||||
|
(symbolp first-elem)
|
||||||
|
(or (assoc first-elem tp-layer-alist)
|
||||||
|
(assoc first-elem tp-layer-groups)))
|
||||||
|
;; It's a layer/group name wrapped in a list - recurse with the symbol
|
||||||
|
(tp--resolve-props first-elem)
|
||||||
|
;; Normal plist processing
|
||||||
(let* ((existing-tp-name (plist-get props 'tp-name))
|
(let* ((existing-tp-name (plist-get props 'tp-name))
|
||||||
(reactive-syms (tp--collect-reactive-symbols props)))
|
(reactive-syms (tp--collect-reactive-symbols props)))
|
||||||
(if reactive-syms
|
(if reactive-syms
|
||||||
@ -2373,7 +2385,7 @@ For group names, includes `tp-layers' property with the full layer stack."
|
|||||||
(if existing-tp-name
|
(if existing-tp-name
|
||||||
props
|
props
|
||||||
(let ((layer-name (tp--generate-anonymous-layer-name)))
|
(let ((layer-name (tp--generate-anonymous-layer-name)))
|
||||||
(append props (list 'tp-name layer-name)))))))
|
(append props (list 'tp-name layer-name)))))))))
|
||||||
;; Symbol - check if it's a layer or group name
|
;; Symbol - check if it's a layer or group name
|
||||||
((symbolp props)
|
((symbolp props)
|
||||||
(cond
|
(cond
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user