mirror of
https://github.com/penpot/penpot.git
synced 2025-08-07 14:38:33 +02:00
🐛 Remove leaks of selrect attrs in the root shape object.
This commit is contained in:
parent
fd91a7b1f4
commit
4bdaab637c
4 changed files with 39 additions and 62 deletions
|
@ -48,11 +48,7 @@
|
||||||
(update :y inc-y))))]
|
(update :y inc-y))))]
|
||||||
(-> shape
|
(-> shape
|
||||||
(update :x inc-x)
|
(update :x inc-x)
|
||||||
(update :x1 inc-x)
|
|
||||||
(update :x2 inc-x)
|
|
||||||
(update :y inc-y)
|
(update :y inc-y)
|
||||||
(update :y1 inc-y)
|
|
||||||
(update :y2 inc-y)
|
|
||||||
(update-in [:selrect :x] inc-x)
|
(update-in [:selrect :x] inc-x)
|
||||||
(update-in [:selrect :x1] inc-x)
|
(update-in [:selrect :x1] inc-x)
|
||||||
(update-in [:selrect :x2] inc-x)
|
(update-in [:selrect :x2] inc-x)
|
||||||
|
@ -197,11 +193,10 @@
|
||||||
(us/assert number? width)
|
(us/assert number? width)
|
||||||
(us/assert number? height)
|
(us/assert number? height)
|
||||||
(-> shape
|
(-> shape
|
||||||
(assoc :width width
|
(assoc :width width :height height)
|
||||||
:height height
|
(update :selrect (fn [shape]
|
||||||
:x2 (+ (:x1 shape) width)
|
(assoc :x2 (+ (:x1 shape) width)
|
||||||
:y2 (+ (:y1 shape) height))
|
:y2 (+ (:y1 shape) height))))))
|
||||||
(update :selrect (nilf #(resize % width height)))))
|
|
||||||
|
|
||||||
;; --- Setup (Initialize)
|
;; --- Setup (Initialize)
|
||||||
|
|
||||||
|
@ -247,30 +242,16 @@
|
||||||
(declare group->rect-shape)
|
(declare group->rect-shape)
|
||||||
(declare rect->rect-shape)
|
(declare rect->rect-shape)
|
||||||
|
|
||||||
|
;; TODO: completly remove
|
||||||
|
|
||||||
(defn shape->rect-shape
|
(defn shape->rect-shape
|
||||||
"Coerce shape to rect like shape."
|
"Coerce shape to rect like shape."
|
||||||
|
|
||||||
[{:keys [type] :as shape}]
|
[{:keys [type] :as shape}]
|
||||||
(case type
|
(case type
|
||||||
(:curve :path) (path->rect-shape shape)
|
(:curve :path) (path->rect-shape shape)
|
||||||
(rect->rect-shape shape)))
|
(rect->rect-shape shape)))
|
||||||
|
|
||||||
(defn shapes->rect-shape
|
|
||||||
[shapes]
|
|
||||||
(let [shapes (mapv shape->rect-shape shapes)
|
|
||||||
minx (transduce (map :x1) min ##Inf shapes)
|
|
||||||
miny (transduce (map :y1) min ##Inf shapes)
|
|
||||||
maxx (transduce (map :x2) max ##-Inf shapes)
|
|
||||||
maxy (transduce (map :y2) max ##-Inf shapes)]
|
|
||||||
{:x1 minx
|
|
||||||
:y1 miny
|
|
||||||
:x2 maxx
|
|
||||||
:y2 maxy
|
|
||||||
:x minx
|
|
||||||
:y miny
|
|
||||||
:width (- maxx minx)
|
|
||||||
:height (- maxy miny)
|
|
||||||
:type :rect}))
|
|
||||||
|
|
||||||
;; -- Points
|
;; -- Points
|
||||||
|
|
||||||
(declare transform-shape-point)
|
(declare transform-shape-point)
|
||||||
|
@ -603,10 +584,10 @@
|
||||||
|
|
||||||
(defn pad-selrec
|
(defn pad-selrec
|
||||||
([selrect] (pad-selrec selrect 1))
|
([selrect] (pad-selrec selrect 1))
|
||||||
([selrec size]
|
([selrect size]
|
||||||
(let [inc #(+ % size)
|
(let [inc #(+ % size)
|
||||||
dec #(- % size)]
|
dec #(- % size)]
|
||||||
(-> selrec
|
(-> selrect
|
||||||
(update :x dec)
|
(update :x dec)
|
||||||
(update :y dec)
|
(update :y dec)
|
||||||
(update :x1 dec)
|
(update :x1 dec)
|
||||||
|
@ -728,10 +709,6 @@
|
||||||
(-> rect-shape
|
(-> rect-shape
|
||||||
(update :x check)
|
(update :x check)
|
||||||
(update :y check)
|
(update :y check)
|
||||||
(update :x1 check)
|
|
||||||
(update :y1 check)
|
|
||||||
(update :x2 check)
|
|
||||||
(update :y2 check)
|
|
||||||
(update :width (comp to-positive check))
|
(update :width (comp to-positive check))
|
||||||
(update :height (comp to-positive check)))))
|
(update :height (comp to-positive check)))))
|
||||||
|
|
||||||
|
|
|
@ -67,8 +67,7 @@
|
||||||
(letfn [(resize-shape [{:keys [x y width height] :as shape} point lock? point-snap]
|
(letfn [(resize-shape [{:keys [x y width height] :as shape} point lock? point-snap]
|
||||||
(let [;; The new shape behaves like a resize on the bottom-right corner
|
(let [;; The new shape behaves like a resize on the bottom-right corner
|
||||||
initial (gpt/point (+ x width) (+ y height))
|
initial (gpt/point (+ x width) (+ y height))
|
||||||
shape' (geom/shape->rect-shape shape)
|
shapev (gpt/point width height)
|
||||||
shapev (gpt/point (:width shape') (:height shape'))
|
|
||||||
deltav (gpt/to-vec initial point-snap)
|
deltav (gpt/to-vec initial point-snap)
|
||||||
scalev (gpt/divide (gpt/add shapev deltav) shapev)
|
scalev (gpt/divide (gpt/add shapev deltav) shapev)
|
||||||
scalev (if lock?
|
scalev (if lock?
|
||||||
|
@ -87,6 +86,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [{:keys [flags]} (:workspace-local state)
|
(let [{:keys [flags]} (:workspace-local state)
|
||||||
|
|
||||||
stoper? #(or (ms/mouse-up? %) (= % :interrupt))
|
stoper? #(or (ms/mouse-up? %) (= % :interrupt))
|
||||||
stoper (rx/filter stoper? stream)
|
stoper (rx/filter stoper? stream)
|
||||||
initial @ms/mouse-position
|
initial @ms/mouse-position
|
||||||
|
@ -95,12 +95,8 @@
|
||||||
objects (get-in state [:workspace-data page-id :objects])
|
objects (get-in state [:workspace-data page-id :objects])
|
||||||
layout (get state :workspace-layout)
|
layout (get state :workspace-layout)
|
||||||
|
|
||||||
frames (->> objects
|
frames (cp/select-frames objects)
|
||||||
vals
|
fid (or (->> frames
|
||||||
(filter (comp #{:frame} :type))
|
|
||||||
(remove #(= (:id %) uuid/zero) ))
|
|
||||||
|
|
||||||
frame-id (or (->> frames
|
|
||||||
(filter #(geom/has-point? % initial))
|
(filter #(geom/has-point? % initial))
|
||||||
first
|
first
|
||||||
:id)
|
:id)
|
||||||
|
@ -109,23 +105,27 @@
|
||||||
shape (-> state
|
shape (-> state
|
||||||
(get-in [:workspace-local :drawing])
|
(get-in [:workspace-local :drawing])
|
||||||
(geom/setup {:x (:x initial) :y (:y initial) :width 1 :height 1})
|
(geom/setup {:x (:x initial) :y (:y initial) :width 1 :height 1})
|
||||||
(assoc :frame-id frame-id)
|
(assoc :frame-id fid)
|
||||||
(assoc ::initialized? true))]
|
(assoc ::initialized? true))]
|
||||||
(rx/concat
|
(rx/concat
|
||||||
|
;; Add shape to drawing state
|
||||||
(rx/of #(assoc-in state [:workspace-local :drawing] shape))
|
(rx/of #(assoc-in state [:workspace-local :drawing] shape))
|
||||||
|
|
||||||
|
;; Initial SNAP
|
||||||
(->> (snap/closest-snap-point page-id [shape] layout initial)
|
(->> (snap/closest-snap-point page-id [shape] layout initial)
|
||||||
(rx/map (fn [{:keys [x y]}]
|
(rx/map (fn [{:keys [x y]}]
|
||||||
#(-> %
|
#(update-in % [:workspace-local :drawing] assoc :x x :y y))))
|
||||||
(assoc-in [:workspace-local :drawing :x] x)
|
|
||||||
(assoc-in [:workspace-local :drawing :y] y)))))
|
|
||||||
|
|
||||||
(->> ms/mouse-position
|
(->> ms/mouse-position
|
||||||
(rx/with-latest vector ms/mouse-position-ctrl)
|
(rx/with-latest vector ms/mouse-position-ctrl)
|
||||||
(rx/switch-map (fn [[point :as current]]
|
(rx/switch-map
|
||||||
|
(fn [[point :as current]]
|
||||||
(->> (snap/closest-snap-point page-id [shape] layout point)
|
(->> (snap/closest-snap-point page-id [shape] layout point)
|
||||||
(rx/map #(conj current %)))))
|
(rx/map #(conj current %)))))
|
||||||
(rx/map (fn [[pt ctrl? point-snap]] #(update-drawing % pt ctrl? point-snap)))
|
(rx/map
|
||||||
|
(fn [[pt ctrl? point-snap]]
|
||||||
|
#(update-drawing % pt ctrl? point-snap)))
|
||||||
|
|
||||||
(rx/take-until stoper))
|
(rx/take-until stoper))
|
||||||
(rx/of handle-finish-drawing)))))))
|
(rx/of handle-finish-drawing)))))))
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
(defn- calculate-dimensions
|
(defn- calculate-dimensions
|
||||||
[{:keys [objects] :as data} vport]
|
[{:keys [objects] :as data} vport]
|
||||||
(let [shapes (cp/select-toplevel-shapes objects {:include-frames? true})]
|
(let [shapes (cp/select-toplevel-shapes objects {:include-frames? true})]
|
||||||
(->> (geom/shapes->rect-shape shapes)
|
(->> (geom/selection-rect shapes)
|
||||||
(geom/adjust-to-viewport vport)
|
(geom/adjust-to-viewport vport)
|
||||||
(geom/fix-invalid-rect-values))))
|
(geom/fix-invalid-rect-values))))
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
[objects]
|
[objects]
|
||||||
(let [shapes (->> (cp/select-toplevel-shapes objects {:include-frames? true})
|
(let [shapes (->> (cp/select-toplevel-shapes objects {:include-frames? true})
|
||||||
(map #(merge % (select-keys % [:x :y :width :height]))))
|
(map #(merge % (select-keys % [:x :y :width :height]))))
|
||||||
bounds (geom/shapes->rect-shape shapes)
|
bounds (geom/selection-rect shapes)
|
||||||
bounds #js {:x (:x bounds)
|
bounds #js {:x (:x bounds)
|
||||||
:y (:y bounds)
|
:y (:y bounds)
|
||||||
:width (:width bounds)
|
:width (:width bounds)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue