🐛 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:
Andrey Antukh 2026-07-16 12:19:50 +02:00 committed by GitHub
parent b3105e6b82
commit 258dd6ad6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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]