mirror of
https://github.com/penpot/penpot.git
synced 2025-02-23 07:16:07 -05:00
♻️ Use constant for zero width space
This commit is contained in:
parent
8992eb98ec
commit
4c6f086f82
1 changed files with 6 additions and 5 deletions
|
@ -43,6 +43,7 @@
|
||||||
(def mentions-context (mf/create-context nil))
|
(def mentions-context (mf/create-context nil))
|
||||||
(def r-mentions-split #"@\[[^\]]*\]\([^\)]*\)")
|
(def r-mentions-split #"@\[[^\]]*\]\([^\)]*\)")
|
||||||
(def r-mentions #"@\[([^\]]*)\]\(([^\)]*)\)")
|
(def r-mentions #"@\[([^\]]*)\]\(([^\)]*)\)")
|
||||||
|
(def zero-width-space \u200B)
|
||||||
|
|
||||||
(defn- parse-comment
|
(defn- parse-comment
|
||||||
"Parse a comment into its elements (texts and mentions)"
|
"Parse a comment into its elements (texts and mentions)"
|
||||||
|
@ -78,7 +79,7 @@
|
||||||
([text]
|
([text]
|
||||||
(-> (dom/create-element "span")
|
(-> (dom/create-element "span")
|
||||||
(dom/set-data! "type" "text")
|
(dom/set-data! "type" "text")
|
||||||
(dom/set-html! (if (empty? text) "​" text)))))
|
(dom/set-html! (if (empty? text) zero-width-space text)))))
|
||||||
|
|
||||||
(defn- create-mention-node
|
(defn- create-mention-node
|
||||||
"Creates a mention node"
|
"Creates a mention node"
|
||||||
|
@ -127,7 +128,7 @@
|
||||||
(or (str/blank? content)
|
(or (str/blank? content)
|
||||||
(str/empty? content)
|
(str/empty? content)
|
||||||
;; If only one char and it's the zero-width whitespace
|
;; If only one char and it's the zero-width whitespace
|
||||||
(and (= 1 (count content)) (= (first content) \u200B))))
|
(and (= 1 (count content)) (= (first content) zero-width-space))))
|
||||||
|
|
||||||
;; Component that renders the component content
|
;; Component that renders the component content
|
||||||
(mf/defc comment-content*
|
(mf/defc comment-content*
|
||||||
|
@ -183,7 +184,7 @@
|
||||||
;; If a node is empty we set the content to "empty"
|
;; If a node is empty we set the content to "empty"
|
||||||
(when (and (= (dom/get-data child-node "type") "text")
|
(when (and (= (dom/get-data child-node "type") "text")
|
||||||
(empty? (dom/get-text child-node)))
|
(empty? (dom/get-text child-node)))
|
||||||
(dom/set-html! child-node "​"))
|
(dom/set-html! child-node zero-width-space))
|
||||||
|
|
||||||
;; Remove mentions that have been modified
|
;; Remove mentions that have been modified
|
||||||
(when (and (= (dom/get-data child-node "type") "mention")
|
(when (and (= (dom/get-data child-node "type") "mention")
|
||||||
|
@ -301,7 +302,7 @@
|
||||||
after-span (create-text-node (dm/str " " suffix))
|
after-span (create-text-node (dm/str " " suffix))
|
||||||
sel (wapi/get-selection)]
|
sel (wapi/get-selection)]
|
||||||
|
|
||||||
(dom/set-html! span-node (if (empty? prefix) "​" prefix))
|
(dom/set-html! span-node (if (empty? prefix) zero-width-space prefix))
|
||||||
(dom/insert-after! node span-node mention-span)
|
(dom/insert-after! node span-node mention-span)
|
||||||
(dom/insert-after! node mention-span after-span)
|
(dom/insert-after! node mention-span after-span)
|
||||||
(wapi/set-cursor-after! after-span)
|
(wapi/set-cursor-after! after-span)
|
||||||
|
@ -368,7 +369,7 @@
|
||||||
|
|
||||||
(when span-node
|
(when span-node
|
||||||
(let [txt (.-textContent span-node)]
|
(let [txt (.-textContent span-node)]
|
||||||
(dom/set-html! span-node (dm/str (subs txt 0 offset) "\n​" (subs txt offset)))
|
(dom/set-html! span-node (dm/str (subs txt 0 offset) "\n" zero-width-space (subs txt offset)))
|
||||||
(wapi/set-cursor! span-node (inc offset))
|
(wapi/set-cursor! span-node (inc offset))
|
||||||
(handle-input)))))
|
(handle-input)))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue