From 107d607d3778124d0d1a861c2c78864fff1d8704 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 15 Mar 2023 09:25:52 +0100 Subject: [PATCH] :bug: Fix error with empty curves --- .../main/data/workspace/drawing/curve.cljs | 3 +- frontend/src/app/util/path/format.cljs | 33 +++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/frontend/src/app/main/data/workspace/drawing/curve.cljs b/frontend/src/app/main/data/workspace/drawing/curve.cljs index 5f8a8e34f..307f0973a 100644 --- a/frontend/src/app/main/data/workspace/drawing/curve.cljs +++ b/frontend/src/app/main/data/workspace/drawing/curve.cljs @@ -49,7 +49,8 @@ (let [objects (wsh/lookup-page-objects state) content (get-in state [:workspace-drawing :object :content] []) - position (gpt/point (get-in content [0 :params] nil)) + start (get-in content [0 :params] nil) + position (when start (gpt/point start)) frame-id (ctst/top-nested-frame objects position) flex-layout? (ctl/flex-layout? objects frame-id) drop-index (when flex-layout? (gsl/get-drop-index frame-id objects position))] diff --git a/frontend/src/app/util/path/format.cljs b/frontend/src/app/util/path/format.cljs index e9c36d50d..f7628bc33 100644 --- a/frontend/src/app/util/path/format.cljs +++ b/frontend/src/app/util/path/format.cljs @@ -112,20 +112,25 @@ (update command :params assoc :x x :y y)) (defn format-path [content] - (let [result (make-array (count content))] - (reduce (fn [last-move current] - (let [point (upc/command->point current) - current-move? (= :move-to (:command current)) - last-move (if current-move? point last-move)] + (try + (let [result (make-array (count content))] + (reduce (fn [last-move current] + (let [point (upc/command->point current) + current-move? (= :move-to (:command current)) + last-move (if current-move? point last-move)] - (if (and (not current-move?) (pt= last-move point)) - (arr/conj! result (command->string (set-point current last-move))) - (arr/conj! result (command->string current))) + (if (and (not current-move?) (pt= last-move point)) + (arr/conj! result (command->string (set-point current last-move))) + (arr/conj! result (command->string current))) - (when (and (not current-move?) (pt= last-move point)) - (arr/conj! result "Z")) + (when (and (not current-move?) (pt= last-move point)) + (arr/conj! result "Z")) - last-move)) - nil - content) - (.join ^js result ""))) + last-move)) + nil + content) + (.join ^js result "")) + + (catch :default err + (.error js/console err) + nil)))