diff --git a/frontend/src/app/main/ui/workspace/shapes/path/editor.cljs b/frontend/src/app/main/ui/workspace/shapes/path/editor.cljs index e716223909..d49422542b 100644 --- a/frontend/src/app/main/ui/workspace/shapes/path/editor.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/path/editor.cljs @@ -36,6 +36,9 @@ (def path-preview-dasharray 4) (def path-snap-stroke-width 1) +;; Stand-in for shapes that reach the editor without content. +(def ^:private empty-content (path/content nil)) + (def accent-color "var(--color-accent-tertiary)") (def secondary-color "var(--color-accent-quaternary)") (def black-color "var(--app-black)") @@ -502,7 +505,7 @@ (some? drag-handler)) base-content - (get shape :content) + (or (get shape :content) empty-content) ;; Cache segment midpoints used by insertion previews. insertion-mid-points diff --git a/frontend/src/app/main/ui/workspace/viewport/drawarea.cljs b/frontend/src/app/main/ui/workspace/viewport/drawarea.cljs index 910688658f..b24cc5e8a5 100644 --- a/frontend/src/app/main/ui/workspace/viewport/drawarea.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/drawarea.cljs @@ -35,6 +35,17 @@ (update fill :fill-opacity #(* (or % 1) edit-fill-opacity))) fills)) +(defn draw-area-kind + "Returns the overlay to render for the drawing object `shape`: + `:path`, `:curve`, `:generic` or nil. Non-path objects always get the + generic overlay, because the active tool can change while a box + drawing is still in progress." + [tool shape] + (cond + (not= :path (dm/get-prop shape :type)) :generic + (= tool :path) :path + (= tool :curve) :curve)) + (defn path-edit-shape "Builds the path shape rendered during editing." [drawing-obj stored] @@ -98,15 +109,8 @@ [:g {:style {:pointer-events "none"}} [:& shapes/shape-wrapper {:shape render-shape}]] - (cond - (= tool :path) - [:> path-draw-area* props] - - (= tool :curve) - [:& path-shape {:shape shape :zoom zoom}] - - (= (:type shape) :path) - nil - - :else - [:> generic-draw-area* props])])) + (case (draw-area-kind tool shape) + :path [:> path-draw-area* props] + :curve [:& path-shape {:shape shape :zoom zoom}] + :generic [:> generic-draw-area* props] + nil)])) diff --git a/frontend/test/frontend_tests/runner.cljs b/frontend/test/frontend_tests/runner.cljs index 7a7da64b1a..598e9faac4 100644 --- a/frontend/test/frontend_tests/runner.cljs +++ b/frontend/test/frontend_tests/runner.cljs @@ -103,6 +103,7 @@ [frontend-tests.ui.comment-input-ime-test] [frontend-tests.ui.comments-clustering-test] [frontend-tests.ui.comments-position-modifier-test] + [frontend-tests.ui.drawarea-test] [frontend-tests.ui.ds-controls-numeric-input-test] [frontend-tests.ui.gradient-handlers-test] [frontend-tests.ui.history-test] @@ -238,6 +239,7 @@ 'frontend-tests.ui.comment-input-ime-test 'frontend-tests.ui.comments-clustering-test 'frontend-tests.ui.comments-position-modifier-test + 'frontend-tests.ui.drawarea-test 'frontend-tests.ui.ds-controls-numeric-input-test 'frontend-tests.ui.gradient-handlers-test 'frontend-tests.ui.history-test diff --git a/frontend/test/frontend_tests/ui/drawarea_test.cljs b/frontend/test/frontend_tests/ui/drawarea_test.cljs new file mode 100644 index 0000000000..7bb715fc8f --- /dev/null +++ b/frontend/test/frontend_tests/ui/drawarea_test.cljs @@ -0,0 +1,28 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; Copyright (c) KALEIDOS SUBSIDIARY SL + +(ns frontend-tests.ui.drawarea-test + (:require + [app.common.types.shape :as cts] + [app.main.ui.workspace.viewport.drawarea :as drawarea] + [cljs.test :as t :include-macros true])) + +(def ^:private box-types + [:rect :frame :circle :text]) + +(t/deftest box-drawings-get-the-generic-overlay-for-any-tool + (doseq [type box-types + tool [:path :curve type nil]] + (let [shape (cts/setup-shape {:type type :x 10 :y 10 :width 0.01 :height 0.01})] + (t/is (= :generic (drawarea/draw-area-kind tool shape)) + (str "type " type " with tool " tool))))) + +(t/deftest path-drawings-follow-the-active-tool + (let [shape (cts/setup-shape {:type :path})] + (t/is (= :path (drawarea/draw-area-kind :path shape))) + (t/is (= :curve (drawarea/draw-area-kind :curve shape))) + (t/is (nil? (drawarea/draw-area-kind :line shape))) + (t/is (nil? (drawarea/draw-area-kind nil shape)))))