🐛 Keep the image when Selected colors changes a text color (#13313)

color-att->text built the text fill without the :image of the color,
so picking an image in Selected colors left a fill with only
:fill-opacity. The backend rejected the text as an invalid shape. The
same gap made an image fill impossible to match, so changing it back
to a plain color did nothing.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
Eva Marco 2026-11-25 12:42:21 +01:00 committed by GitHub
parent 571ee80a4b
commit 6337810676
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 1 deletions

View File

@ -642,7 +642,8 @@
:fill-opacity (:opacity color)
:fill-color-ref-id (:ref-id color)
:fill-color-ref-file (:ref-file color)
:fill-color-gradient (:gradient color)}))
:fill-color-gradient (:gradient color)
:fill-image (:image color)}))
(defn- change-text-color
[old-color new-color index node]

View File

@ -7,6 +7,7 @@
(ns frontend-tests.data.workspace-colors-test
(:require
[app.common.schema :as sm]
[app.common.types.fills :as types.fills]
[app.common.types.shape :as cts]
[app.common.uuid :as uuid]
[app.main.data.workspace.colors :as dwc]
@ -170,3 +171,29 @@
(t/is (= 2 (count @calls)))
(t/is (= "#ff0000" (:color (first @calls))))
(t/is (= image (:image (second @calls))))))
(def ^:private text-image
{:id #uuid "00000000-0000-0000-0000-000000000001"
:width 100
:height 100
:mtype "image/png"})
(t/deftest change-text-color-sets-an-image
;; Regression for https://github.com/penpot/penpot/issues/12463.
;; Picking an image in Selected colors for a text left a fill with only
;; :fill-opacity, which the backend rejects as an invalid shape.
(let [node {:text "Night" :fills [{:fill-color "#000000" :fill-opacity 1}]}
result (#'dwc/change-text-color {:color "#000000" :opacity 1}
{:image text-image :opacity 0.9}
0
node)]
(t/is (= [{:fill-image text-image :fill-opacity 0.9}] (:fills result)))
(t/is (sm/validate types.fills/schema:fill (first (:fills result))))))
(t/deftest change-text-color-replaces-an-image
(let [node {:text "Night" :fills [{:fill-image text-image :fill-opacity 1}]}
result (#'dwc/change-text-color {:image text-image :opacity 1}
{:color "#fabada" :opacity 1}
0
node)]
(t/is (= [{:fill-color "#fabada" :fill-opacity 1}] (:fills result)))))