0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-26 00:19:07 -05:00

🐛 Fix problem when alt+drag duplicate frames

This commit is contained in:
alonso.torres 2022-03-29 18:02:09 +02:00 committed by Andrey Antukh
parent 4a3fb55b30
commit 5633291ab0
4 changed files with 35 additions and 9 deletions

View file

@ -194,7 +194,8 @@
(ptk/reify ::initialize-page (ptk/reify ::initialize-page
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(when-not (contains? (get-in state [:workspace-data :pages-index]) page-id) (if (contains? (get-in state [:workspace-data :pages-index]) page-id)
(rx/of (dwp/preload-data-uris))
(let [default-page-id (get-in state [:workspace-data :pages 0])] (let [default-page-id (get-in state [:workspace-data :pages 0])]
(rx/of (go-to-page default-page-id))))) (rx/of (go-to-page default-page-id)))))

View file

@ -14,6 +14,7 @@
[app.common.spec.change :as spec.change] [app.common.spec.change :as spec.change]
[app.common.spec.file :as spec.file] [app.common.spec.file :as spec.file]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.config :as cfg]
[app.main.data.dashboard :as dd] [app.main.data.dashboard :as dd]
[app.main.data.events :as ev] [app.main.data.events :as ev]
[app.main.data.fonts :as df] [app.main.data.fonts :as df]
@ -653,6 +654,9 @@
frame-changes (->> stream frame-changes (->> stream
(rx/filter dch/commit-changes?) (rx/filter dch/commit-changes?)
;; Async so we wait for additional side-effects of commit-changes
(rx/observe-on :async)
(rx/filter (comp not thumbnail-change?)) (rx/filter (comp not thumbnail-change?))
(rx/with-latest-from objects-stream) (rx/with-latest-from objects-stream)
(rx/map extract-frame-changes) (rx/map extract-frame-changes)
@ -678,3 +682,26 @@
(rx/buffer-until (->> frame-changes (rx/debounce 1000))) (rx/buffer-until (->> frame-changes (rx/debounce 1000)))
(rx/flat-map #(reduce set/union %)) (rx/flat-map #(reduce set/union %))
(rx/map #(update-frame-thumbnail %))))))))) (rx/map #(update-frame-thumbnail %)))))))))
(defn preload-data-uris
"Preloads the image data so it's ready when necesary"
[]
(ptk/reify ::preload-data-uris
ptk/WatchEvent
(watch [_ state _]
(let [extract-urls
(fn [{:keys [metadata fill-image]}]
(cond
(some? metadata)
[(cfg/resolve-file-media metadata)]
(some? fill-image)
[(cfg/resolve-file-media fill-image)]))
uris (into #{}
(comp (mapcat extract-urls)
(filter some?))
(vals (wsh/lookup-page-objects state)))]
(->> (rx/from uris)
(rx/merge-map #(http/fetch-data-uri % false))
(rx/ignore))))))

View file

@ -503,6 +503,7 @@
id-duplicated (when (= (count selected) 1) (first selected))] id-duplicated (when (= (count selected) 1) (first selected))]
;; Warning: This order is important for the focus mode.
(rx/of (dch/commit-changes changes) (rx/of (dch/commit-changes changes)
(select-shapes selected) (select-shapes selected)
(memorize-duplicated id-original id-duplicated))))))) (memorize-duplicated id-original id-duplicated)))))))

View file

@ -7,6 +7,7 @@
(ns app.main.ui.shapes.text.fontfaces (ns app.main.ui.shapes.text.fontfaces
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.pages.helpers :as cph]
[app.main.fonts :as fonts] [app.main.fonts :as fonts]
[app.main.ui.hooks :as hooks] [app.main.ui.hooks :as hooks]
[app.main.ui.shapes.embed :as embed] [app.main.ui.shapes.embed :as embed]
@ -76,14 +77,10 @@
{::mf/wrap-props false {::mf/wrap-props false
::mf/wrap [#(mf/memo' % (mf/check-props ["shapes"]))]} ::mf/wrap [#(mf/memo' % (mf/check-props ["shapes"]))]}
[props] [props]
(let [shapes (->> (obj/get props "shapes") (let [;; Retrieve the fonts ids used by the text shapes
(filterv #(= :text (:type %)))) fonts (->> (obj/get props "shapes")
(filterv cph/text-shape?)
content (->> shapes (mapv :content)) (mapv (comp fonts/get-content-fonts :content))
;; Retrieve the fonts ids used by the text shapes
fonts (->> content
(mapv fonts/get-content-fonts)
(reduce set/union #{}) (reduce set/union #{})
(hooks/use-equal-memo))] (hooks/use-equal-memo))]