diff --git a/common/src/app/common/data.cljc b/common/src/app/common/data.cljc index 5006d0c47..80268f617 100644 --- a/common/src/app/common/data.cljc +++ b/common/src/app/common/data.cljc @@ -82,15 +82,22 @@ "Assoc a k v pair, in the order position just before the other key." [o ks k v before-k] (let [f (fn [o'] - (cond-> (reduce - (fn [acc [k' v']] - (cond - (and before-k (= k' before-k)) (assoc acc k v k' v') - (= k k') acc - :else (assoc acc k' v'))) - (ordered-map) - o') - (not before-k) (assoc k v)))] + (let [found (volatile! false) + result (reduce + (fn [acc [k' v']] + (cond + (and before-k (= k' before-k)) + (do + (vreset! found true) + (assoc acc k v k' v')) + + (= k k') acc + :else (assoc acc k' v'))) + (ordered-map) + o')] + (if (or (not before-k) (not @found)) + (assoc result k v) + result)))] (if (seq ks) (oupdate-in o ks f) (f o)))) diff --git a/common/src/app/common/logic/tokens.cljc b/common/src/app/common/logic/tokens.cljc index 3e7ca4a08..39f2374bf 100644 --- a/common/src/app/common/logic/tokens.cljc +++ b/common/src/app/common/logic/tokens.cljc @@ -65,13 +65,7 @@ to (nth tree to-index) before (case position :top to - :bot (let [v (nth tree (inc to-index) nil)] - ;; if the next index is a group, we need to set it as - ;; nil because if we set a path on different subpath, - ;; the move algorightm will simply remove the set - (if (:group? v) - nil - v)) + :bot (nth tree (inc to-index) nil) :center nil) prev-before (if (:group? from) @@ -87,6 +81,7 @@ (= :bot position) (:group? to) (not (get collapsed-paths (:path to))))) + from-path (:path from) to-parent-path (if drop-as-direct-group-child? (:path to)