mirror of
https://github.com/penpot/penpot.git
synced 2025-12-12 06:24:17 +01:00
♻️ Remove redundant flag on text overrides (#6933)
This commit is contained in:
@@ -1665,27 +1665,62 @@
|
||||
:shapes all-parents})]))))
|
||||
|
||||
|
||||
(defn- text-partial-change-value
|
||||
[touched-content untouched-content touched]
|
||||
(cond
|
||||
(touched :text-content-structure-same-attrs)
|
||||
(if (touched :text-content-attribute)
|
||||
;; Both structure and attrs has been touched, keep the
|
||||
(defn- text-change-value
|
||||
[touched-content ;; The :content of the copy text before updating
|
||||
untouched-content ;; The :content of the main component
|
||||
touched]
|
||||
|
||||
(let [main-comps-diff (cttx/get-diff-type touched-content untouched-content)
|
||||
diff-structure? (contains? main-comps-diff :text-content-structure)
|
||||
|
||||
touched-attrs (cttx/get-first-paragraph-text-attrs touched-content)
|
||||
;; Have touched content an uniform style?
|
||||
thed-unif-style? (cttx/equal-attrs? touched-content touched-attrs)
|
||||
|
||||
untouched-attrs (cttx/get-first-paragraph-text-attrs untouched-content)
|
||||
;; Have untouched content an uniform style?
|
||||
untched-unif-style? (cttx/equal-attrs? untouched-content untouched-attrs)]
|
||||
(cond
|
||||
;; Both text and attrs has been touched, keep the
|
||||
;; touched-content
|
||||
(and (touched :text-content-text) (touched :text-content-attribute))
|
||||
touched-content
|
||||
;; Keep the touched-content structure and texts, update
|
||||
;; its attrs to make them like the untouched-content
|
||||
(cttx/copy-attrs-keys touched-content (cttx/get-first-paragraph-text-attrs untouched-content)))
|
||||
|
||||
(touched :text-content-text)
|
||||
;; Keep the texts touched in touched-content, so copy the
|
||||
;; texts from touched-content into untouched-content
|
||||
(cttx/copy-text-keys touched-content untouched-content)
|
||||
(touched :text-content-structure)
|
||||
;; Special case for adding or removing paragraphs:
|
||||
;; If the structure has been touched, but the attrs don't,
|
||||
;; and both have uniform attributes, we keep the touched-content structure and
|
||||
;; texts, updating its attrs to make them like the untouched-content
|
||||
(if (and (not (touched :text-content-attribute)) thed-unif-style? untched-unif-style?)
|
||||
(cttx/copy-attrs-keys touched-content untouched-attrs)
|
||||
;; In other case, we keep the touched content
|
||||
touched-content)
|
||||
|
||||
(touched :text-content-text)
|
||||
;; Keep the texts touched in touched-content, so copy the
|
||||
;; texts from touched-content into untouched-content
|
||||
(cttx/copy-text-keys touched-content untouched-content)
|
||||
|
||||
(touched :text-content-attribute)
|
||||
;; The untouched content has a different structure, but the touched content had't
|
||||
;; touched the structure
|
||||
(if diff-structure?
|
||||
;; If both have uniform attributes, we keep the untouched-content structure and
|
||||
;; texts, updating its attrs to make them like the touched-content
|
||||
(if (and thed-unif-style? untched-unif-style?)
|
||||
(cttx/copy-attrs-keys untouched-content touched-attrs)
|
||||
;; In other case, we keep the touched content
|
||||
touched-content)
|
||||
|
||||
;; Keep the attrs touched in touched-content, so copy the
|
||||
;; texts from untouched-content into touched-content
|
||||
(cttx/copy-text-keys untouched-content touched-content))
|
||||
|
||||
|
||||
;; Nothing is touched
|
||||
:else
|
||||
untouched-content)))
|
||||
|
||||
(touched :text-content-attribute)
|
||||
;; Keep the attrs touched in touched-content, so copy the
|
||||
;; texts from untouched-content into touched-content
|
||||
(cttx/copy-text-keys untouched-content touched-content)))
|
||||
|
||||
(defn- add-update-attr-operations
|
||||
[attr dest-shape roperations uoperations attr-val]
|
||||
@@ -1700,34 +1735,6 @@
|
||||
[(conj roperations roperation)
|
||||
(conj uoperations uoperation)]))
|
||||
|
||||
(defn- is-text-partial-change?
|
||||
"Check if the attr update is a text partial change"
|
||||
[untouched-shape touched-shape]
|
||||
(let [touched (get touched-shape :touched #{})
|
||||
partial-text-keys [:text-content-attribute :text-content-text]
|
||||
active-keys (filter touched partial-text-keys)
|
||||
untouched-content (:content untouched-shape)
|
||||
untouched-attrs (cttx/get-first-paragraph-text-attrs untouched-content)
|
||||
eq-untouched-attrs? (cttx/equal-attrs? untouched-content untouched-attrs)]
|
||||
(and
|
||||
(or
|
||||
;; One and only one of the keys is pressent
|
||||
(= 1 (count active-keys))
|
||||
(and
|
||||
(not (touched :text-content-attribute))
|
||||
(touched :text-content-structure-same-attrs)))
|
||||
|
||||
(or
|
||||
;; Both has the same structure
|
||||
(cttx/equal-structure? untouched-content (:content touched-shape))
|
||||
|
||||
;; The origin and destiny have different structures, but each have the same attrs
|
||||
;; for all the items on its content tree
|
||||
(and
|
||||
eq-untouched-attrs?
|
||||
(touched :text-content-structure-same-attrs))))))
|
||||
|
||||
|
||||
(defn- update-attrs
|
||||
"The main function that implements the attribute sync algorithm. Copy
|
||||
attributes that have changed in the origin shape to the dest shape.
|
||||
@@ -1784,13 +1791,13 @@
|
||||
;; and attrs (bold, font, etc) are in the same attr :content.
|
||||
;; If only one of them is touched, we want to adress this case and
|
||||
;; only update the untouched one
|
||||
text-partial-change?
|
||||
(when (and
|
||||
omit-touched?
|
||||
(cfh/text-shape? origin-shape)
|
||||
(= :content attr)
|
||||
(touched attr-group))
|
||||
(is-text-partial-change? origin-shape dest-shape))
|
||||
text-content-change?
|
||||
(and
|
||||
omit-touched?
|
||||
(cfh/text-shape? origin-shape)
|
||||
(= :content attr)
|
||||
(touched attr-group))
|
||||
|
||||
|
||||
skip-operations?
|
||||
(or (= (get origin-shape attr) (get dest-shape attr))
|
||||
@@ -1799,7 +1806,7 @@
|
||||
;; When it is a text-partial-change, we should generate operations
|
||||
;; even when omit-touched? is true, but updating only the text or
|
||||
;; the attributes, omiting the other part
|
||||
(not text-partial-change?)))
|
||||
(not text-content-change?)))
|
||||
|
||||
attr-val (when-not skip-operations?
|
||||
(cond
|
||||
@@ -1808,10 +1815,10 @@
|
||||
reset-pos-data?
|
||||
nil
|
||||
|
||||
text-partial-change?
|
||||
(text-partial-change-value (:content dest-shape)
|
||||
(:content origin-shape)
|
||||
touched)
|
||||
text-content-change?
|
||||
(text-change-value (:content dest-shape)
|
||||
(:content origin-shape)
|
||||
touched)
|
||||
|
||||
:else
|
||||
(get origin-shape attr)))
|
||||
@@ -1824,7 +1831,7 @@
|
||||
;; On a text-partial-change, we want to force a position-data reset
|
||||
;; so it's calculated again
|
||||
[roperations uoperations]
|
||||
(if (and text-partial-change? (not skip-operations?))
|
||||
(if (and text-content-change? (not skip-operations?))
|
||||
(add-update-attr-operations :position-data dest-shape roperations uoperations nil)
|
||||
[roperations uoperations])
|
||||
|
||||
|
||||
@@ -83,21 +83,12 @@
|
||||
compare them, and returns a set with the type of differences.
|
||||
The possibilities are
|
||||
:text-content-text
|
||||
:text-content-attribute,
|
||||
:text-content-structure
|
||||
:text-content-structure-same-attrs."
|
||||
:text-content-attribute
|
||||
:text-content-structure"
|
||||
[a b]
|
||||
(let [diff-type (compare-text-content a b
|
||||
{:text-cb (fn [acc] (conj acc :text-content-text))
|
||||
:attribute-cb (fn [acc _] (conj acc :text-content-attribute))})]
|
||||
(if-not (contains? diff-type :text-content-structure)
|
||||
diff-type
|
||||
(let [;; get attrs of the first paragraph of the first paragraph-set
|
||||
attrs (get-first-paragraph-text-attrs a)]
|
||||
(if (and (equal-attrs? a attrs)
|
||||
(equal-attrs? b attrs))
|
||||
#{:text-content-structure :text-content-structure-same-attrs}
|
||||
diff-type)))))
|
||||
(compare-text-content a b
|
||||
{:text-cb (fn [acc] (conj acc :text-content-text))
|
||||
:attribute-cb (fn [acc _] (conj acc :text-content-attribute))}))
|
||||
|
||||
(defn get-diff-attrs
|
||||
"Given two content text structures, conformed by maps and vectors,
|
||||
|
||||
@@ -103,7 +103,7 @@
|
||||
|
||||
file' (thf/apply-changes file changes)
|
||||
copy-child' (ths/get-shape file' :copy-child)]
|
||||
(t/is (= #{:content-group :text-content-structure :text-content-structure-same-attrs} (:touched copy-child')))))
|
||||
(t/is (= #{:content-group :text-content-structure} (:touched copy-child')))))
|
||||
|
||||
(t/deftest test-text-copy-changed-structure-diff-attrs
|
||||
(let [;; ==== Setup
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
(t/is (= #{:text-content-attribute} diff-attr))
|
||||
(t/is (= #{:text-content-text :text-content-attribute} diff-both))
|
||||
(t/is (= #{:text-content-structure} diff-structure))
|
||||
(t/is (= #{:text-content-structure :text-content-structure-same-attrs} diff-structure-same-attrs))))
|
||||
(t/is (= #{:text-content-structure} diff-structure-same-attrs))))
|
||||
|
||||
|
||||
(t/deftest test-get-diff-attrs
|
||||
|
||||
Reference in New Issue
Block a user