From 9652996f07f18a79dd2e9221cab931974e8c9a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Tue, 2 Sep 2025 11:38:45 +0200 Subject: [PATCH] :bug: Add validation for text shapes with wrong register of overrides --- common/src/app/common/files/repair.cljc | 13 +++++++++++++ common/src/app/common/files/validate.cljc | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/common/src/app/common/files/repair.cljc b/common/src/app/common/files/repair.cljc index 1d638586ee..945b0c1f57 100644 --- a/common/src/app/common/files/repair.cljc +++ b/common/src/app/common/files/repair.cljc @@ -491,6 +491,19 @@ (pcb/with-library-data file-data) (pcb/update-component (:id shape) repair-component)))) +(defmethod repair-error :invalid-text-touched + [_ {:keys [shape page-id] :as error} file-data _] + (let [repair-shape + (fn [shape] + ;; Add content group + (log/debug :hint " -> add :content-group to :touched-groups") + (update shape :touched ctk/set-touched-group :content-group))] + + (log/dbg :hint "repairing shape :invalid-text-touched" :id (:id shape) :name (:name shape) :page-id page-id) + (-> (pcb/empty-changes nil page-id) + (pcb/with-file-data file-data) + (pcb/update-shapes [(:id shape)] repair-shape)))) + (defmethod repair-error :misplaced-slot [_ {:keys [shape page-id] :as error} file-data _] (let [repair-shape diff --git a/common/src/app/common/files/validate.cljc b/common/src/app/common/files/validate.cljc index 75650ca97d..02887b5f5e 100644 --- a/common/src/app/common/files/validate.cljc +++ b/common/src/app/common/files/validate.cljc @@ -57,6 +57,7 @@ :not-component-not-allowed :component-nil-objects-not-allowed :instance-head-not-frame + :invalid-text-touched :misplaced-slot :missing-slot :shape-ref-cycle @@ -328,6 +329,20 @@ "This shape has children with the same swap slot" shape file page))) +(defn- check-valid-touched + "Validate that the text touched flags are coherent." + [shape file page] + (let [touched-groups (ctk/normal-touched-groups shape) + content-touched? (touched-groups :content-group) + text-touched? (or (touched-groups :text-content-text) + (touched-groups :text-content-attribute) + (touched-groups :text-content-structure))] + ;; For now we only check this combination, that has been reported in some bugs + (when (and text-touched? (not content-touched?)) + (report-error :invalid-text-touched + "This thape has text type touched but not content touched" + shape file page)))) + (defn- check-shape-main-root-top "Root shape of a top main instance: @@ -369,6 +384,7 @@ (check-component-ref shape file page libraries) (check-empty-swap-slot shape file page) (check-duplicate-swap-slot shape file page) + (check-valid-touched shape file page) (run! #(check-shape % file page libraries :context :copy-top :library-exists library-exists) (:shapes shape)))) (defn- check-shape-copy-root-nested @@ -379,6 +395,7 @@ [shape file page libraries library-exists] (check-component-not-main-head shape file page libraries) (check-component-not-root shape file page) + (check-valid-touched shape file page) ;; We can have situations where the nested copy and the ancestor copy come from different libraries and some of them have been dettached ;; so we only validate the shape-ref if the ancestor is from a valid library (when library-exists @@ -401,6 +418,7 @@ (check-component-not-root shape file page) (check-component-ref shape file page libraries) (check-empty-swap-slot shape file page) + (check-valid-touched shape file page) (run! #(check-shape % file page libraries :context :copy-any) (:shapes shape))) (defn- check-shape-not-component