mirror of
https://github.com/penpot/penpot.git
synced 2026-07-20 21:17:44 +00:00
🐛 Handle text node targets in closest-text-editor-content (#10641)
Event targets can be DOM text nodes (nodeType 3) which lack the .closest() method. Add a get-element helper that normalizes text nodes to their parent Element before calling .closest(), matching the existing pattern in dom/get-parent-with-data. Fixes #10640 AI-assisted-by: mimo-v2.5-pro
This commit is contained in:
parent
b3105e6b82
commit
258dd6ad6c
@ -10,13 +10,23 @@
|
||||
[app.main.store :as st]
|
||||
[app.util.dom :as dom]))
|
||||
|
||||
(defn- get-element
|
||||
"Given a DOM node, returns the nearest Element, walking up from text nodes."
|
||||
[target]
|
||||
(if (and (some? target)
|
||||
(not= (.-nodeType target) js/Node.ELEMENT_NODE))
|
||||
(.-parentElement target)
|
||||
target))
|
||||
|
||||
(defn v1-closest-text-editor-content
|
||||
[target]
|
||||
(.closest ^js target ".public-DraftEditor-content"))
|
||||
(when-let [el (get-element target)]
|
||||
(.closest ^js el ".public-DraftEditor-content")))
|
||||
|
||||
(defn v2-closest-text-editor-content
|
||||
[target]
|
||||
(.closest ^js target "[data-itype=\"editor\"]"))
|
||||
(when-let [el (get-element target)]
|
||||
(.closest ^js el "[data-itype=\"editor\"]")))
|
||||
|
||||
(defn closest-text-editor-content
|
||||
[target]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user