🐛 Give a color to the stroke created when its style changes (#13264)

* 🐛 Give a color to the stroke created when its style changes

Changing the width, style or alignment of a stroke that a shape did not
have built the stroke from the style attributes only, with no color. The
backend rejected the shape as invalid.

Start from the default stroke, as the per-side width and the stroke width
tokens already do.

Closes #13263

AI-assisted-by: claude-opus-5-5

* 🐛 Read bool strokes in the multiple selection menu

The bool type lacked :strokes in its editable attrs, so the multiple
selection menu ignored bool strokes. With a bool without strokes and a
shape with one selected, the menu showed that stroke as shared, and
editing it created a stroke on the bool. Two bools with the same stroke
showed none.

Relates to #13263

AI-assisted-by: claude-opus-5-5
This commit is contained in:
Eva Marco 2026-11-24 14:34:28 +01:00 committed by GitHub
parent bc3f8dd6ef
commit 271f5af784
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 66 additions and 10 deletions

View File

@ -505,6 +505,7 @@
:fill-color-ref-file
:fill-color-gradient
:strokes
:stroke-style
:stroke-alignment
:stroke-width

View File

@ -407,6 +407,18 @@
:changed-item-index index)]
(dwsh/update-shapes ids #(update-shape-stroke-color % index color) options)))))))
(defn update-shape-stroke-attrs
"Update the style attributes of the stroke on the specified `position`.
When the shape has no stroke there, a default one is created: a stroke
built from style attributes alone would have no color, which is not a
valid stroke."
[shape position attrs]
(let [stroke (or (get-in shape [:strokes position]) cts/default-stroke)]
(-> shape
(update :strokes #(or % []))
(assoc-in [:strokes position]
(merge stroke (build-stroke-style-attrs stroke) attrs)))))
(defn change-stroke-attrs
([ids attrs index] (change-stroke-attrs ids attrs index nil))
([ids attrs index options]
@ -419,16 +431,7 @@
:changed-item-index index)]
(rx/of (dwsh/update-shapes
ids
(fn [shape]
(let [stroke (get-in shape [:strokes index])
style-attrs (build-stroke-style-attrs stroke)
attrs (merge stroke style-attrs attrs)]
(cond-> shape
(not (contains? shape :strokes))
(assoc :strokes [])
:always
(assoc-in [:strokes index] attrs))))
#(update-shape-stroke-attrs % index attrs)
options)))))))
;; --- Stroke side width

View File

@ -6,6 +6,8 @@
(ns frontend-tests.data.workspace-colors-test
(:require
[app.common.schema :as sm]
[app.common.types.shape :as cts]
[app.common.uuid :as uuid]
[app.main.data.workspace.colors :as dwc]
[clojure.test :as t]
@ -47,6 +49,27 @@
(t/is (thrown? js/Error
(ptk/event? (dwc/add-fill #{uuid/zero} color4 1))))))
(t/deftest update-shape-stroke-attrs-changes-an-existing-stroke
(let [shape {:strokes [{:stroke-color "#000000" :stroke-opacity 1
:stroke-width 1 :stroke-style :solid
:stroke-alignment :inner}]}
result (dwc/update-shape-stroke-attrs shape 0 {:stroke-width 4})]
(t/is (= {:stroke-color "#000000" :stroke-opacity 1
:stroke-width 4 :stroke-style :solid
:stroke-alignment :inner}
(get-in result [:strokes 0])))))
(t/deftest update-shape-stroke-attrs-creates-a-stroke-with-color
;; Regression for https://github.com/penpot/penpot/issues/12463.
;; A stroke built from style attributes alone has no color, so the
;; backend rejects the shape as invalid.
(let [result (dwc/update-shape-stroke-attrs {:type :bool} 0 {:stroke-width 4})
stroke (get-in result [:strokes 0])]
(t/is (= 1 (count (:strokes result))))
(t/is (= "#000000" (:stroke-color stroke)))
(t/is (= 4 (:stroke-width stroke)))
(t/is (sm/validate cts/schema:stroke stroke))))
(t/deftest update-colorpicker-color-skips-add-recent-on-incomplete-image-state
;; Regression for https://github.com/penpot/penpot/issues/8443.

View File

@ -10,6 +10,7 @@
[app.config :as cf]
[app.main.ui.workspace.sidebar.options.menus.stroke :as stroke]
[app.main.ui.workspace.sidebar.options.rows.stroke-row :as stroke-row]
[app.main.ui.workspace.sidebar.options.shapes.multiple :as multiple]
[clojure.test :as t :include-macros true]))
(def ^:private per-side-flags (conj cf/flags :stroke-per-side))
@ -93,3 +94,31 @@
{:stroke-width-top "sw" :stroke-width-left "other"} true)))
(t/is (nil? (stroke-row/stroke-width-input-token
{:stroke-width-left "other"} true)))))
(def ^:private solid-stroke
{:stroke-color "#000000"
:stroke-opacity 1
:stroke-width 1
:stroke-style :solid
:stroke-alignment :inner})
(defn- multiple-stroke-values
[shapes]
(let [[_ids values _tokens] (multiple/get-attrs* shapes {} :stroke)]
values))
(t/deftest multiple-selection-reads-bool-strokes-test
;; Regression for https://github.com/penpot/penpot/issues/13263: the
;; menu ignored the bool strokes, showed the rect stroke as shared and
;; editing it created a stroke on the bool.
(t/testing "a bool without strokes and a rect with one are mixed"
(t/is (= :multiple
(:strokes (multiple-stroke-values
[{:id :bool-a :type :bool :strokes []}
{:id :rect-a :type :rect :strokes [solid-stroke]}])))))
(t/testing "bools with the same stroke share it"
(t/is (= [solid-stroke]
(:strokes (multiple-stroke-values
[{:id :bool-a :type :bool :strokes [solid-stroke]}
{:id :bool-b :type :bool :strokes [solid-stroke]}]))))))