mirror of
https://github.com/penpot/penpot.git
synced 2026-04-25 11:18:36 +00:00
🐛 Guard delete undo against missing sibling order (#8858)
Return nil from get-prev-sibling when the shape is no longer present in the parent ordering so delete undo generation falls back to index-based restore instead of crashing on invalid vector access.
This commit is contained in:
parent
8c1cf3623b
commit
0337607a1b
@ -355,7 +355,8 @@
|
||||
prt (get objects pid)
|
||||
shapes (:shapes prt)
|
||||
pos (d/index-of shapes id)]
|
||||
(if (= 0 pos) nil (nth shapes (dec pos)))))
|
||||
(when (and (some? pos) (pos? pos))
|
||||
(nth shapes (dec pos)))))
|
||||
|
||||
(defn get-immediate-children
|
||||
"Retrieve resolved shape objects that are immediate children
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
(ns common-tests.files.helpers-test
|
||||
(:require
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.uuid :as uuid]
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/deftest test-generate-unique-name
|
||||
@ -36,3 +37,19 @@
|
||||
#{"base-name 1" "base-name 2"}
|
||||
:immediate-suffix? true)
|
||||
"base-name 3")))
|
||||
|
||||
(t/deftest test-get-prev-sibling
|
||||
(let [parent-id (uuid/custom 1 1)
|
||||
child-a (uuid/custom 1 2)
|
||||
child-b (uuid/custom 1 3)
|
||||
orphan-id (uuid/custom 1 4)
|
||||
objects {parent-id {:id parent-id :shapes [child-a child-b]}
|
||||
child-a {:id child-a :parent-id parent-id}
|
||||
child-b {:id child-b :parent-id parent-id}
|
||||
orphan-id {:id orphan-id :parent-id parent-id}}]
|
||||
(t/testing "Returns previous sibling when present in parent ordering"
|
||||
(t/is (= child-a
|
||||
(cfh/get-prev-sibling objects child-b))))
|
||||
|
||||
(t/testing "Returns nil when the shape is missing from parent ordering"
|
||||
(t/is (nil? (cfh/get-prev-sibling objects orphan-id))))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user