0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 16:30:37 -05:00

Merge pull request #2896 from penpot/eva-bugfixing-6

🐛 Fix paste a frame inside itself
This commit is contained in:
Pablo Alba 2023-02-08 12:16:09 +01:00 committed by GitHub
commit 8e35ad0f7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 28 deletions

View file

@ -1,5 +1,10 @@
# CHANGELOG # CHANGELOG
## 1.17.2
### :bug: Bugs fixed
- Fix paste board inside itself [Taiga #4775](https://tree.taiga.io/project/penpot/issue/4775)
## 1.17.1 ## 1.17.1
### :bug: Bugs fixed ### :bug: Bugs fixed

View file

@ -1440,6 +1440,19 @@
(and (= 1 (count selected)) (and (= 1 (count selected))
(= :frame (get-in objects [(first selected) :type]))))) (= :frame (get-in objects [(first selected) :type])))))
(defn same-frame-from-selected? [state frame-id]
(let [selected (wsh/lookup-selected state)]
(contains? frame-id (first selected))))
(defn frame-same-size?
[paste-obj frame-obj]
(and
(= (:heigth (:selrect (first (vals paste-obj))))
(:heigth (:selrect frame-obj)))
(= (:width (:selrect (first (vals paste-obj))))
(:width (:selrect frame-obj)))))
(defn- paste-shape (defn- paste-shape
[{selected :selected [{selected :selected
paste-objects :objects ;; rename this because here comes only the clipboard shapes, paste-objects :objects ;; rename this because here comes only the clipboard shapes,
@ -1480,17 +1493,31 @@
(calculate-paste-position [state mouse-pos in-viewport?] (calculate-paste-position [state mouse-pos in-viewport?]
(let [page-objects (wsh/lookup-page-objects state) (let [page-objects (wsh/lookup-page-objects state)
selected-objs (map #(get paste-objects %) selected) selected-objs (map #(get paste-objects %) selected)
first-selected-obj (first selected-objs)
page-selected (wsh/lookup-selected state) page-selected (wsh/lookup-selected state)
wrapper (gsh/selection-rect selected-objs) wrapper (gsh/selection-rect selected-objs)
orig-pos (gpt/point (:x1 wrapper) (:y1 wrapper))] orig-pos (gpt/point (:x1 wrapper) (:y1 wrapper))
frame-id (first page-selected)
frame-object (get page-objects frame-id)
base (cph/get-base-shape page-objects page-selected)
index (cph/get-position-on-parent page-objects (:id base))]
(cond (cond
;; Pasting inside a frame
(selected-frame? state) (selected-frame? state)
(let [frame-id (first page-selected)
frame-object (get page-objects frame-id)
origin-frame-id (:frame-id (first selected-objs)) (if (or (same-frame-from-selected? state (first (vals paste-objects)))
(frame-same-size? paste-objects frame-object))
;; Paste next to selected frame, if selected is itself or of the same size as the copied
(let [selected-frame-obj (get page-objects (first page-selected))
parent-id (:parent-id base)
paste-x (+ (:width selected-frame-obj) (:x selected-frame-obj) 50)
paste-y (:y selected-frame-obj)
delta (gpt/subtract (gpt/point paste-x paste-y) orig-pos)]
[(:frame-id base) parent-id delta index])
;; Paste inside selected frame otherwise
(let [origin-frame-id (:frame-id first-selected-obj)
origin-frame-object (get page-objects origin-frame-id) origin-frame-object (get page-objects origin-frame-id)
margin-x (-> (- (:width origin-frame-object) (+ (:x wrapper) (:width wrapper))) margin-x (-> (- (:width origin-frame-object) (+ (:x wrapper) (:width wrapper)))
@ -1516,7 +1543,7 @@
;; - Align it to the limits on the x and y axis ;; - Align it to the limits on the x and y axis
;; - Respect the distance of the object to the right and bottom in the original frame ;; - Respect the distance of the object to the right and bottom in the original frame
(gpt/point paste-x paste-y))] (gpt/point paste-x paste-y))]
[frame-id frame-id delta]) [frame-id frame-id delta]))
(empty? page-selected) (empty? page-selected)
(let [frame-id (ctst/top-nested-frame page-objects mouse-pos) (let [frame-id (ctst/top-nested-frame page-objects mouse-pos)
@ -1524,9 +1551,7 @@
[frame-id frame-id delta]) [frame-id frame-id delta])
:else :else
(let [base (cph/get-base-shape page-objects page-selected) (let [frame-id (:frame-id base)
index (cph/get-position-on-parent page-objects (:id base))
frame-id (:frame-id base)
parent-id (:parent-id base) parent-id (:parent-id base)
delta (if in-viewport? delta (if in-viewport?
(gpt/subtract mouse-pos orig-pos) (gpt/subtract mouse-pos orig-pos)