Address code review feedback: use helper function for layer props update

Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-12-28 10:31:31 +00:00
parent 094f8f0f88
commit fefe5873ed
2 changed files with 10 additions and 4 deletions

View File

@ -3066,7 +3066,10 @@ the source text should be used and the reactive variable should be updated."
(should (equal (tp-at 0 'tp-text result) "2")))
;; Now set the variable to a different value and test again
(setq tp-test-text-var "18")
;; Redefine layer to reset resolved props
;; Redefine layer to reset resolved props to the new variable value.
;; This is necessary because the layer definition caches the resolved
;; tp-text value, and we want to test the behavior when the variable
;; already has a non-nil value at layer application time.
(tp-define-layer 'test-init-text-layer
:props '(face bold tp-text $tp-test-text-var))
(let ((result (tp-set "2" 'test-init-text-layer)))

9
tp.el
View File

@ -668,13 +668,16 @@ NEW-OBJECT is the new string object (only different for strings with tp-text)."
;; This ensures the reactive variable and buffer text stay in sync
(when-let ((layer-name (plist-get props 'tp-name)))
(when-let ((reactive-var (tp--find-tp-text-reactive-var layer-name)))
;; Update the reactive variable with the current text (buffer-local)
;; Update the reactive variable with the current text
;; Note: Using global `set` here because the layer definition is global.
;; When the variable is changed, the reactive watcher will update all
;; buffers that have this layer applied.
(set reactive-var current-text)
;; Also update the layer definition so future accesses see the new value
(let ((layer-props (cdr (assoc layer-name tp-layer-alist))))
(when layer-props
(setf (cdr (assoc layer-name tp-layer-alist))
(plist-put layer-props 'tp-text current-text))))))
(tp--set-layer-props layer-name
(plist-put layer-props 'tp-text current-text))))))
(list (plist-put props 'tp-text current-text) end object)))
;; tp-text has a string value - replace the text in the region
((stringp tp-text-val)