🐛 Fix vertical positioning.

This commit is contained in:
Andrey Antukh 2020-06-15 14:02:58 +02:00 committed by Andrés Moya
parent 65c9c46a22
commit 1dfc604cf0
4 changed files with 39 additions and 171 deletions

View file

@ -748,23 +748,33 @@
(ptk/reify ::vertical-order-selected-shpes
ptk/WatchEvent
(watch [_ state stream]
(let [page-id (:current-page-id state)
objects (get-in state [:workspace-data page-id :objects])
selected (seq (get-in state [:workspace-local :selected]))
(let [page-id (:current-page-id state)
objects (get-in state [:workspace-data page-id :objects])
selected (get-in state [:workspace-local :selected])
rchanges (mapv (fn [id]
(let [frame-id (get-in objects [id :frame-id])]
{:type :mod-obj
:id frame-id
:operations [{:type :rel-order :id id :loc loc}]}))
(let [obj (get objects id)
parent (get objects (:parent-id obj))
shapes (:shapes parent)
cindex (d/index-of shapes id)
nindex (case loc
:top (count shapes)
:down (max 0 (- cindex 1))
:up (min (count shapes) (+ (inc cindex) 1))
:bottom 0)]
{:type :mov-objects
:parent-id (:parent-id obj)
:frame-id (:frame-id obj)
:index nindex
:shapes [id]}))
selected)
uchanges (mapv (fn [id]
(let [frame-id (get-in objects [id :frame-id])
shapes (get-in objects [frame-id :shapes])
cindex (d/index-of shapes id)]
{:type :mod-obj
:id frame-id
:operations [{:type :abs-order :id id :index cindex}]}))
uchanges (mapv (fn [id]
(let [obj (get objects id)]
{:type :mov-objects
:parent-id (:parent-id obj)
:frame-id (:frame-id obj)
:shapes [id]
:index (cph/position-on-parent id objects)}))
selected)]
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true}))))))

View file

@ -76,24 +76,25 @@
[ma mb]
(let [ma-keys (set (keys ma))
mb-keys (set (keys mb))
added (set/difference mb-keys ma-keys)
added (set/difference mb-keys ma-keys)
removed (set/difference ma-keys mb-keys)
both (set/intersection ma-keys mb-keys)]
both (set/intersection ma-keys mb-keys)]
(d/concat
(mapv #(array-map :type :set :attr % :val (get mb %)) added)
(mapv #(array-map :type :set :attr % :val nil) removed)
(loop [k (first both)
r (rest both)
rs []]
(if k
(let [vma (get ma k)
(loop [items (seq both)
result []]
(if items
(let [k (first items)
vma (get ma k)
vmb (get mb k)]
(if (= vma vmb)
(recur (first r) (rest r) rs)
(recur (first r) (rest r) (conj rs {:type :set
:attr k
:val vmb}))))
rs)))))
(recur (next items) result)
(recur (next items)
(conj result {:type :set
:attr k
:val vmb}))))
result)))))
(defn- generate-changes
[prev curr]