Skip to content

Commit ec021d9

Browse files
committed
Merge remote-tracking branch 'origin/staging' into develop
2 parents f1a6b46 + 3d0c301 commit ec021d9

23 files changed

Lines changed: 433 additions & 340 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ on-premises instances** that want to keep up to date.
7272
- Fix button width [Taiga #11394](https://tree.taiga.io/project/penpot/issue/11394)
7373
- Fix mixed letter spacing and line height [Taiga #11178](https://tree.taiga.io/project/penpot/issue/11178)
7474
- Fix snap nodes shortcut [Taiga #11054](https://tree.taiga.io/project/penpot/issue/11054)
75+
- Fix changing a text property in a text layer does not unapply the previously applied token in the same property [Taiga #11337}(https://tree.taiga.io/project/penpot/issue/11337)
7576

7677
## 2.7.2
7778

common/src/app/common/files/changes_builder.cljc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@
161161
(contains? (meta changes) ::file-data)
162162
"Call (with-file-data) before using this function"))
163163

164-
165164
(defn- lookup-objects
166165
[changes]
167166
(let [data (::file-data (meta changes))]

common/src/app/common/logic/shapes.cljc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,30 @@
1616
[app.common.types.pages-list :as ctpl]
1717
[app.common.types.shape.interactions :as ctsi]
1818
[app.common.types.shape.layout :as ctl]
19+
[app.common.types.text :as ctt]
1920
[app.common.types.token :as cto]
20-
[app.common.uuid :as uuid]))
21+
[app.common.uuid :as uuid]
22+
[clojure.set :as set]))
2123

2224
(defn- generate-unapply-tokens
2325
"When updating attributes that have a token applied, we must unapply it, because the value
2426
of the attribute now has been given directly, and does not come from the token."
2527
[changes objects changed-sub-attr]
26-
(let [mod-obj-changes (->> (:redo-changes changes)
28+
(let [new-objects (pcb/get-objects changes)
29+
mod-obj-changes (->> (:redo-changes changes)
2730
(filter #(= (:type %) :mod-obj)))
2831

32+
text-changed-attrs
33+
(fn [shape]
34+
(let [new-shape (get new-objects (:id shape))
35+
attrs (ctt/get-diff-attrs (:content shape) (:content new-shape))]
36+
(apply set/union (map cto/shape-attr->token-attrs attrs))))
37+
2938
check-attr (fn [shape changes attr]
3039
(let [tokens (get shape :applied-tokens {})
31-
token-attrs (cto/shape-attr->token-attrs attr changed-sub-attr)]
40+
token-attrs (if (or (not= (:type shape) :text) (not= attr :content))
41+
(cto/shape-attr->token-attrs attr changed-sub-attr)
42+
(text-changed-attrs shape))]
3243
(if (some #(contains? tokens %) token-attrs)
3344
(pcb/update-shapes changes [(:id shape)] #(cto/unapply-token-id % token-attrs))
3445
changes)))

common/src/app/common/test_helpers/compositions.cljc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
(merge shape
3838
text-params))))
3939

40-
41-
4240
(defn add-frame
4341
[file frame-label & {:keys [] :as params}]
4442
;; Generated shape tree:

common/src/app/common/test_helpers/shapes.cljc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
[app.common.files.helpers :as cfh]
1212
[app.common.test-helpers.files :as thf]
1313
[app.common.test-helpers.ids-map :as thi]
14+
[app.common.text :as txt]
1415
[app.common.types.color :as ctc]
1516
[app.common.types.container :as ctn]
1617
[app.common.types.pages-list :as ctpl]
@@ -81,6 +82,21 @@
8182
(:id page)
8283
#(ctst/set-shape % (ctn/set-shape-attr shape attr val)))))))
8384

85+
(defn update-shape-text
86+
[file shape-label attr val & {:keys [page-label]}]
87+
(let [page (if page-label
88+
(thf/get-page file page-label)
89+
(thf/current-page file))
90+
shape (ctst/get-shape page (thi/id shape-label))]
91+
(update file :data
92+
(fn [file-data]
93+
(ctpl/update-page file-data
94+
(:id page)
95+
#(ctst/set-shape % (txt/update-text-content shape
96+
txt/is-content-node?
97+
d/txt-merge
98+
{attr val})))))))
99+
84100
(defn sample-library-color
85101
[label & {:keys [name path color opacity gradient image]}]
86102
(-> {:id (thi/new-id! label)

common/src/app/common/types/path/segment.cljc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,6 @@
470470
"Given a content and a set of points return all the segments in the path
471471
that uses the points"
472472
[content points]
473-
(assert (impl/path-data? content) "expected path data instance")
474-
475473
(let [point-set (set points)]
476474
(loop [result (transient [])
477475
prev-point nil

common/src/app/common/types/text.cljc

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111

1212
(defn- compare-text-content
1313
"Given two content text structures, conformed by maps and vectors,
14-
compare them, and returns a set with the type of differences.
15-
The possibilities are :text-content-text :text-content-attribute and :text-content-structure."
16-
[a b]
14+
compare them, and returns a set with the differences info.
15+
If the structures are equal, it returns an empty set. If the structure
16+
has changed, it returns :text-content-structure. There are two
17+
callbacks to specify what to return when there is a text change with
18+
the same structure, and when attributes change."
19+
[a b {:keys [text-cb attribute-cb] :as callbacks}]
1720
(cond
1821
;; If a and b are equal, there is no diff
1922
(= a b)
@@ -38,26 +41,25 @@
3841
#{:text-content-structure}
3942
(into acc
4043
(apply set/union
41-
(map #(compare-text-content %1 %2) v1 v2))))
44+
(map #(compare-text-content %1 %2 callbacks) v1 v2))))
4245

4346
;; If the key is :text, and they are different, it is a text differece
4447
(= k :text)
4548
(if (not= v1 v2)
46-
(conj acc :text-content-text)
49+
(text-cb acc)
4750
acc)
4851

4952
:else
5053
;; If the key is not :text, and they are different, it is an attribute differece
5154
(if (not= v1 v2)
52-
(conj acc :text-content-attribute)
55+
(attribute-cb acc k)
5356
acc))))
5457
#{}
5558
keys))
5659

5760
:else
5861
#{:text-content-structure}))
5962

60-
6163
(defn equal-attrs?
6264
"Given a text structure, and a map of attrs, check that all the internal attrs in
6365
paragraphs and sentences have the same attrs"
@@ -79,10 +81,15 @@
7981
(defn get-diff-type
8082
"Given two content text structures, conformed by maps and vectors,
8183
compare them, and returns a set with the type of differences.
82-
The possibilities are :text-content-text :text-content-attribute,
83-
:text-content-structure and :text-content-structure-same-attrs."
84+
The possibilities are
85+
:text-content-text
86+
:text-content-attribute,
87+
:text-content-structure
88+
:text-content-structure-same-attrs."
8489
[a b]
85-
(let [diff-type (compare-text-content a b)]
90+
(let [diff-type (compare-text-content a b
91+
{:text-cb (fn [acc] (conj acc :text-content-text))
92+
:attribute-cb (fn [acc _] (conj acc :text-content-attribute))})]
8693
(if-not (contains? diff-type :text-content-structure)
8794
diff-type
8895
(let [;; get attrs of the first paragraph of the first paragraph-set
@@ -92,6 +99,24 @@
9299
#{:text-content-structure :text-content-structure-same-attrs}
93100
diff-type)))))
94101

102+
(defn get-diff-attrs
103+
"Given two content text structures, conformed by maps and vectors,
104+
compare them, and returns a set with the attributes that have changed.
105+
This is independent of the text structure, so if the structure changes
106+
but the attributes are the same, it will return an empty set."
107+
[a b]
108+
(let [diff-attrs (compare-text-content a b
109+
{:text-cb identity
110+
:attribute-cb (fn [acc attr] (conj acc attr))})]
111+
(if-not (contains? diff-attrs :text-content-structure)
112+
diff-attrs
113+
(let [;; get attrs of the first paragraph of the first paragraph-set
114+
attrs (get-first-paragraph-text-attrs a)]
115+
(if (and (equal-attrs? a attrs)
116+
(equal-attrs? b attrs))
117+
#{}
118+
(disj diff-attrs :text-content-structure))))))
119+
95120
;; TODO We know that there are cases that the blocks of texts are separated
96121
;; differently: ["one" " " "two"], ["one " "two"], ["one" " two"]
97122
;; so this won't work for 100% of the situations. But it's good enough for now,
@@ -116,7 +141,6 @@
116141
:else
117142
true))
118143

119-
120144
(defn copy-text-keys
121145
"Given two equal content text structures, deep copy all the keys :text
122146
from origin to destiny"

common/test/common_tests/logic/token_apply_test.cljc

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
(ns common-tests.logic.token-apply-test
88
(:require
9+
[app.common.data :as d]
910
[app.common.files.changes-builder :as pcb]
1011
[app.common.logic.shapes :as cls]
1112
[app.common.test-helpers.compositions :as tho]
1213
[app.common.test-helpers.files :as thf]
1314
[app.common.test-helpers.ids-map :as thi]
1415
[app.common.test-helpers.shapes :as ths]
1516
[app.common.test-helpers.tokens :as tht]
17+
[app.common.text :as txt]
1618
[app.common.types.container :as ctn]
1719
[app.common.types.token :as cto]
1820
[app.common.types.tokens-lib :as ctob]
@@ -53,7 +55,8 @@
5355
(ctob/make-token :name "token-dimensions"
5456
:type :dimensions
5557
:value 100))))
56-
(tho/add-frame :frame1)))
58+
(tho/add-frame :frame1)
59+
(tho/add-text :text1 "Hello World")))
5760

5861
(defn- apply-all-tokens
5962
[file]
@@ -64,7 +67,8 @@
6467
(tht/apply-token-to-shape :frame1 "token-stroke-width" [:stroke-width] [:stroke-width] 2)
6568
(tht/apply-token-to-shape :frame1 "token-color" [:stroke-color] [:stroke-color] "#00ff00")
6669
(tht/apply-token-to-shape :frame1 "token-color" [:fill] [:fill] "#00ff00")
67-
(tht/apply-token-to-shape :frame1 "token-dimensions" [:width :height] [:width :height] 100)))
70+
(tht/apply-token-to-shape :frame1 "token-dimensions" [:width :height] [:width :height] 100)
71+
(tht/apply-token-to-shape :text1 "token-color" [:fill] [:fill] "#00ff00")))
6872

6973
(t/deftest apply-tokens-to-shape
7074
(let [;; ==== Setup
@@ -171,6 +175,7 @@
171175
(apply-all-tokens))
172176
page (thf/current-page file)
173177
frame1 (ths/get-shape file :frame1)
178+
text1 (ths/get-shape file :text1)
174179

175180
;; ==== Action
176181
changes (-> (-> (pcb/empty-changes nil)
@@ -190,13 +195,25 @@
190195
(ctn/set-shape-attr :width 0)
191196
(ctn/set-shape-attr :height 0)))
192197
(:objects page)
198+
{})
199+
(cls/generate-update-shapes [(:id text1)]
200+
(fn [shape]
201+
(txt/update-text-content
202+
shape
203+
txt/is-content-node?
204+
d/txt-merge
205+
{:fills (ths/sample-fills-color :fill-color "#fabada")}))
206+
(:objects page)
193207
{}))
194208

195209
file' (thf/apply-changes file changes)
196210

197211
;; ==== Get
198-
frame1' (ths/get-shape file' :frame1)
199-
applied-tokens' (:applied-tokens frame1')]
212+
frame1' (ths/get-shape file' :frame1)
213+
text1' (ths/get-shape file' :text1)
214+
applied-tokens-frame' (:applied-tokens frame1')
215+
applied-tokens-text' (:applied-tokens text1')]
200216

201217
;; ==== Check
202-
(t/is (= (count applied-tokens') 0))))
218+
(t/is (= (count applied-tokens-frame') 0))
219+
(t/is (= (count applied-tokens-text') 0))))

common/test/common_tests/types/text_test.cljc

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,33 @@
2929
#(conj % line)))
3030

3131
(t/deftest test-get-diff-type
32-
(let [diff-text (cttx/get-diff-type content-base content-changed-text)
33-
diff-attr (cttx/get-diff-type content-base content-changed-attr)
34-
diff-both (cttx/get-diff-type content-base content-changed-both)
35-
diff-structure (cttx/get-diff-type content-base content-changed-structure)
32+
(let [diff-text (cttx/get-diff-type content-base content-changed-text)
33+
diff-attr (cttx/get-diff-type content-base content-changed-attr)
34+
diff-both (cttx/get-diff-type content-base content-changed-both)
35+
diff-structure (cttx/get-diff-type content-base content-changed-structure)
3636
diff-structure-same-attrs (cttx/get-diff-type content-base content-changed-structure-same-attrs)]
37+
3738
(t/is (= #{:text-content-text} diff-text))
3839
(t/is (= #{:text-content-attribute} diff-attr))
3940
(t/is (= #{:text-content-text :text-content-attribute} diff-both))
4041
(t/is (= #{:text-content-structure} diff-structure))
4142
(t/is (= #{:text-content-structure :text-content-structure-same-attrs} diff-structure-same-attrs))))
4243

4344

45+
(t/deftest test-get-diff-attrs
46+
(let [attrs-text (cttx/get-diff-attrs content-base content-changed-text)
47+
attrs-attr (cttx/get-diff-attrs content-base content-changed-attr)
48+
attrs-both (cttx/get-diff-attrs content-base content-changed-both)
49+
attrs-structure (cttx/get-diff-attrs content-base content-changed-structure)
50+
attrs-structure-same-attrs (cttx/get-diff-attrs content-base content-changed-structure-same-attrs)]
51+
52+
(t/is (= #{} attrs-text))
53+
(t/is (= #{:font-size} attrs-attr))
54+
(t/is (= #{:font-size} attrs-both))
55+
(t/is (= #{} attrs-structure))
56+
(t/is (= #{} attrs-structure-same-attrs))))
57+
58+
4459
(t/deftest test-equal-structure
4560
(t/is (true? (cttx/equal-structure? content-base content-changed-text)))
4661
(t/is (true? (cttx/equal-structure? content-base content-changed-attr)))

frontend/src/app/main/data/workspace/drawing.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
(watch [_ _ _]
9797
(rx/of
9898
(case type
99-
:path (path/handle-new-shape)
99+
:path (path/handle-drawing)
100100
:curve (curve/handle-drawing)
101101
(box/handle-drawing type))))))
102102

0 commit comments

Comments
 (0)