From a85a7d2b2f91f522e9b3d842cfb02533df41f366 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Tue, 8 Oct 2024 17:09:58 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20logic=20in=20oassoc-in-bef?= =?UTF-8?q?ore=20wher=20top=20items=20couldn't=20be=20move=20to=20bottom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/src/app/common/data.cljc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/common/src/app/common/data.cljc b/common/src/app/common/data.cljc index 2d0011be71..89687c7aab 100644 --- a/common/src/app/common/data.cljc +++ b/common/src/app/common/data.cljc @@ -93,16 +93,20 @@ (if-let [index (index-of (keys o) before-k)] (let [new-v (if ks (oassoc-in-before (get o k) before-ks ks v) - v)] + v) + current-index (index-of (keys o) k) + new-index (if (and current-index (< current-index index)) + (dec index) + index)] (if (= k before-k) (-> (ordered-map) - (into (take index o)) + (into (take new-index o)) (assoc k new-v) - (into (drop (inc index) o))) + (into (drop (inc new-index) o))) (-> (ordered-map) - (into (take index o)) + (into (take new-index (dissoc o k))) (assoc k new-v) - (into (drop index o))))) + (into (drop new-index (dissoc o k)))))) (oassoc-in o (cons k ks) v))) (defn vec2