From 258dd6ad6cc634375768f88c6f9fafe63cfd2f36 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 16 Jul 2026 12:19:50 +0200 Subject: [PATCH] :bug: 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 --- frontend/src/app/util/text/ui.cljs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/util/text/ui.cljs b/frontend/src/app/util/text/ui.cljs index 8138126221..a6242cb7e3 100644 --- a/frontend/src/app/util/text/ui.cljs +++ b/frontend/src/app/util/text/ui.cljs @@ -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]