mirror of
https://github.com/penpot/penpot.git
synced 2026-10-29 05:50:35 +00:00
🐛 Fix crash when drawing (#12101)
This commit is contained in:
parent
f962cf487c
commit
0d8bcf9637
@ -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
|
||||
|
||||
@ -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)]))
|
||||
|
||||
@ -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
|
||||
|
||||
28
frontend/test/frontend_tests/ui/drawarea_test.cljs
Normal file
28
frontend/test/frontend_tests/ui/drawarea_test.cljs
Normal file
@ -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)))))
|
||||
Loading…
x
Reference in New Issue
Block a user