mirror of
https://github.com/penpot/penpot.git
synced 2026-11-20 09:00:49 +00:00
🐛 Keep auto-grow text boxes sizing on component copies
This commit is contained in:
parent
d3e2ce2de5
commit
a37ad6161d
@ -879,3 +879,200 @@
|
||||
(t/is (= "14" (:font-size line)))
|
||||
;; The text doesn't change, because the structure was touched
|
||||
(t/is (= "hello world" (:text line)))))
|
||||
|
||||
(t/deftest sync-text-override-with-geometry-touched-keeps-width
|
||||
;; Documents the #12721 gap: text+geometry touched receives font-size from
|
||||
;; main but keeps local width until frontend remasure.
|
||||
(let [;; ==== Setup
|
||||
file0 (-> (thf/sample-file :file1)
|
||||
(tho/add-frame-with-text :main-root :main-child "hello world")
|
||||
(thc/make-component :component1 :main-root)
|
||||
(thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]}))
|
||||
page0 (thf/current-page file0)
|
||||
copy-child (ths/get-shape file0 :copy-child)
|
||||
copy-width (:width copy-child)
|
||||
|
||||
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page0))
|
||||
#{(:id copy-child)}
|
||||
(fn [shape]
|
||||
(-> shape
|
||||
(assoc-in [:content :children 0 :children 0 :children 0 :text] "Hi")
|
||||
(assoc :width (+ copy-width 25)
|
||||
:touched #{:content-group
|
||||
:text-content-text
|
||||
:geometry-group})))
|
||||
(:objects page0)
|
||||
{:ignore-touched true})
|
||||
file (thf/apply-changes file0 changes)
|
||||
main-child (ths/get-shape file :main-child)
|
||||
page (thf/current-page file)
|
||||
copy-before (ths/get-shape file :copy-child)
|
||||
|
||||
;; ==== Action — main font-size change + sync
|
||||
changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||
#{(:id main-child)}
|
||||
(fn [shape]
|
||||
(-> shape
|
||||
(assoc-in [:content :children 0 :children 0 :children 0 :font-size] "32")
|
||||
(assoc :width (+ (:width shape) 50))))
|
||||
(:objects page)
|
||||
{})
|
||||
|
||||
updated-file (thf/apply-changes file changes1)
|
||||
|
||||
changes2 (cll/generate-sync-file-changes (pcb/empty-changes)
|
||||
nil
|
||||
:components
|
||||
(:id updated-file)
|
||||
(thi/id :component1)
|
||||
(:id updated-file)
|
||||
{(:id updated-file) updated-file}
|
||||
(:id updated-file))
|
||||
|
||||
file' (thf/apply-changes updated-file changes2)
|
||||
|
||||
;; ==== Get
|
||||
copy-child' (ths/get-shape file' :copy-child)
|
||||
line (get-in copy-child' [:content :children 0 :children 0 :children 0])]
|
||||
(t/is (= "32" (:font-size line)))
|
||||
(t/is (= "Hi" (:text line)))
|
||||
(t/is (= (:width copy-before) (:width copy-child')))
|
||||
(t/is (contains? (:touched copy-child') :geometry-group))))
|
||||
|
||||
(t/deftest sync-text-only-override-without-geometry-receives-font-size
|
||||
(let [;; ==== Setup
|
||||
file0 (-> (thf/sample-file :file1)
|
||||
(tho/add-frame-with-text :main-root :main-child "hello world")
|
||||
(thc/make-component :component1 :main-root)
|
||||
(thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]}))
|
||||
page0 (thf/current-page file0)
|
||||
copy-child (ths/get-shape file0 :copy-child)
|
||||
|
||||
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page0))
|
||||
#{(:id copy-child)}
|
||||
(fn [shape]
|
||||
(assoc-in shape [:content :children 0 :children 0 :children 0 :text] "Hi"))
|
||||
(:objects page0)
|
||||
{})
|
||||
file (thf/apply-changes file0 changes)
|
||||
main-child (ths/get-shape file :main-child)
|
||||
page (thf/current-page file)
|
||||
copy-mid (ths/get-shape file :copy-child)
|
||||
|
||||
;; ==== Action
|
||||
changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||
#{(:id main-child)}
|
||||
(fn [shape]
|
||||
(assoc-in shape [:content :children 0 :children 0 :children 0 :font-size] "32"))
|
||||
(:objects page)
|
||||
{})
|
||||
|
||||
updated-file (thf/apply-changes file changes1)
|
||||
|
||||
changes2 (cll/generate-sync-file-changes (pcb/empty-changes)
|
||||
nil
|
||||
:components
|
||||
(:id updated-file)
|
||||
(thi/id :component1)
|
||||
(:id updated-file)
|
||||
{(:id updated-file) updated-file}
|
||||
(:id updated-file))
|
||||
|
||||
file' (thf/apply-changes updated-file changes2)
|
||||
copy-child' (ths/get-shape file' :copy-child)
|
||||
line (get-in copy-child' [:content :children 0 :children 0 :children 0])]
|
||||
(t/is (= #{:content-group :text-content-text} (:touched copy-mid)))
|
||||
(t/is (not (contains? (:touched copy-mid) :geometry-group)))
|
||||
(t/is (= "32" (:font-size line)))
|
||||
(t/is (= "Hi" (:text line)))))
|
||||
|
||||
(t/deftest sync-fixed-copy-keeps-grow-type-and-local-width-when-geometry-touched
|
||||
(let [;; ==== Setup
|
||||
file0 (-> (thf/sample-file :file1)
|
||||
(tho/add-frame-with-text :main-root :main-child "hello world"
|
||||
:child-params {:grow-type :fixed :width 120 :height 40})
|
||||
(thc/make-component :component1 :main-root)
|
||||
(thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]}))
|
||||
page0 (thf/current-page file0)
|
||||
copy-child (ths/get-shape file0 :copy-child)
|
||||
|
||||
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page0))
|
||||
#{(:id copy-child)}
|
||||
(fn [shape]
|
||||
(-> shape
|
||||
(assoc :width 200
|
||||
:touched #{:geometry-group})))
|
||||
(:objects page0)
|
||||
{:ignore-touched true})
|
||||
file (thf/apply-changes file0 changes)
|
||||
main-child (ths/get-shape file :main-child)
|
||||
page (thf/current-page file)
|
||||
|
||||
changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||
#{(:id main-child)}
|
||||
(fn [shape]
|
||||
(assoc shape :width 300))
|
||||
(:objects page)
|
||||
{})
|
||||
|
||||
updated-file (thf/apply-changes file changes1)
|
||||
|
||||
changes2 (cll/generate-sync-file-changes (pcb/empty-changes)
|
||||
nil
|
||||
:components
|
||||
(:id updated-file)
|
||||
(thi/id :component1)
|
||||
(:id updated-file)
|
||||
{(:id updated-file) updated-file}
|
||||
(:id updated-file))
|
||||
|
||||
file' (thf/apply-changes updated-file changes2)
|
||||
copy-child' (ths/get-shape file' :copy-child)]
|
||||
(t/is (= :fixed (:grow-type copy-child')))
|
||||
(t/is (= 200 (:width copy-child')))
|
||||
(t/is (contains? (:touched copy-child') :geometry-group))))
|
||||
|
||||
(t/deftest sync-grow-type-override-kept-on-copy
|
||||
(let [;; ==== Setup
|
||||
file0 (-> (thf/sample-file :file1)
|
||||
(tho/add-frame-with-text :main-root :main-child "hello world")
|
||||
(thc/make-component :component1 :main-root)
|
||||
(thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]}))
|
||||
page0 (thf/current-page file0)
|
||||
copy-child (ths/get-shape file0 :copy-child)
|
||||
|
||||
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page0))
|
||||
#{(:id copy-child)}
|
||||
(fn [shape]
|
||||
(assoc shape :grow-type :fixed))
|
||||
(:objects page0)
|
||||
{})
|
||||
file (thf/apply-changes file0 changes)
|
||||
main-child (ths/get-shape file :main-child)
|
||||
page (thf/current-page file)
|
||||
copy-mid (ths/get-shape file :copy-child)
|
||||
|
||||
changes1 (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||
#{(:id main-child)}
|
||||
(fn [shape]
|
||||
(assoc-in shape [:content :children 0 :children 0 :children 0 :font-size] "32"))
|
||||
(:objects page)
|
||||
{})
|
||||
|
||||
updated-file (thf/apply-changes file changes1)
|
||||
|
||||
changes2 (cll/generate-sync-file-changes (pcb/empty-changes)
|
||||
nil
|
||||
:components
|
||||
(:id updated-file)
|
||||
(thi/id :component1)
|
||||
(:id updated-file)
|
||||
{(:id updated-file) updated-file}
|
||||
(:id updated-file))
|
||||
|
||||
file' (thf/apply-changes updated-file changes2)
|
||||
copy-child' (ths/get-shape file' :copy-child)
|
||||
line (get-in copy-child' [:content :children 0 :children 0 :children 0])]
|
||||
(t/is (contains? (:touched copy-mid) :text-font-group))
|
||||
(t/is (= :fixed (:grow-type copy-child')))
|
||||
(t/is (= "32" (:font-size line)))))
|
||||
|
||||
@ -130,3 +130,67 @@
|
||||
copy-child' (ths/get-shape file' :copy-child)]
|
||||
(t/is (= #{:content-group :text-content-structure} (:touched copy-child')))))
|
||||
|
||||
(t/deftest test-text-copy-width-marks-geometry-without-ignore-touched
|
||||
(let [;; ==== Setup
|
||||
file (-> (thf/sample-file :file1)
|
||||
(tho/add-frame-with-text :main-root :main-child "hello world")
|
||||
(thc/make-component :component1 :main-root)
|
||||
(thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]}))
|
||||
page (thf/current-page file)
|
||||
copy-child (ths/get-shape file :copy-child)
|
||||
|
||||
;; ==== Action — documents set-shape-attr: :width marks :geometry-group
|
||||
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||
#{(:id copy-child)}
|
||||
(fn [shape]
|
||||
(assoc shape :width (+ (:width shape) 40)))
|
||||
(:objects page)
|
||||
{})
|
||||
|
||||
file' (thf/apply-changes file changes)
|
||||
copy-child' (ths/get-shape file' :copy-child)]
|
||||
(t/is (contains? (:touched copy-child') :geometry-group))))
|
||||
|
||||
(t/deftest test-text-copy-width-with-ignore-touched-skips-geometry
|
||||
(let [;; ==== Setup
|
||||
file (-> (thf/sample-file :file1)
|
||||
(tho/add-frame-with-text :main-root :main-child "hello world")
|
||||
(thc/make-component :component1 :main-root)
|
||||
(thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]}))
|
||||
page (thf/current-page file)
|
||||
copy-child (ths/get-shape file :copy-child)
|
||||
|
||||
;; ==== Action — contract for content-driven auto-resize commits
|
||||
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||
#{(:id copy-child)}
|
||||
(fn [shape]
|
||||
(assoc shape :width (+ (:width shape) 40)))
|
||||
(:objects page)
|
||||
{:ignore-touched true})
|
||||
|
||||
file' (thf/apply-changes file changes)
|
||||
copy-child' (ths/get-shape file' :copy-child)]
|
||||
(t/is (not (contains? (:touched copy-child') :geometry-group)))))
|
||||
|
||||
(t/deftest test-text-copy-auto-height-height-with-ignore-touched-skips-geometry
|
||||
(let [;; ==== Setup
|
||||
file (-> (thf/sample-file :file1)
|
||||
(tho/add-frame-with-text :main-root :main-child "hello world"
|
||||
:child-params {:grow-type :auto-height})
|
||||
(thc/make-component :component1 :main-root)
|
||||
(thc/instantiate-component :component1 :copy-root {:children-labels [:copy-child]}))
|
||||
page (thf/current-page file)
|
||||
copy-child (ths/get-shape file :copy-child)
|
||||
|
||||
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||
#{(:id copy-child)}
|
||||
(fn [shape]
|
||||
(assoc shape :height (+ (:height shape) 20)))
|
||||
(:objects page)
|
||||
{:ignore-touched true})
|
||||
|
||||
file' (thf/apply-changes file changes)
|
||||
copy-child' (ths/get-shape file' :copy-child)]
|
||||
(t/is (= :auto-height (:grow-type copy-child')))
|
||||
(t/is (not (contains? (:touched copy-child') :geometry-group)))))
|
||||
|
||||
|
||||
@ -1230,6 +1230,22 @@
|
||||
(remove uuid/zero?))
|
||||
(:redo-changes changes)))
|
||||
|
||||
(defn- sync-auto-grow-text-ids-on-page
|
||||
"Auto-grow text ids from sync redo-changes on `page-id`, resolved against
|
||||
pre-commit `objects`. Off-page, non-text, and :fixed ids are excluded."
|
||||
[changes page-id objects]
|
||||
(into []
|
||||
(comp
|
||||
(filter #(= page-id (:page-id %)))
|
||||
(keep :id)
|
||||
(remove uuid/zero?)
|
||||
(filter (fn [id]
|
||||
(when-let [shape (get objects id)]
|
||||
(and (cfh/text-shape? shape)
|
||||
(not= :fixed (:grow-type shape))))))
|
||||
(distinct))
|
||||
(:redo-changes changes)))
|
||||
|
||||
(defn set-updating-library
|
||||
[updating?]
|
||||
(ptk/reify ::set-updating-library
|
||||
@ -1240,30 +1256,55 @@
|
||||
(dissoc state :updating-library)))))
|
||||
|
||||
(defn- sync-file-frontend-events
|
||||
[file-id changes updated-frames undo-group]
|
||||
(rx/concat
|
||||
(rx/of (set-updating-library false)
|
||||
(ntf/hide {:tag :sync-dialog}))
|
||||
(when (seq (:redo-changes changes))
|
||||
(rx/of (dch/commit-changes changes)))
|
||||
(when-not (empty? updated-frames)
|
||||
(let [frames-by-page (group-by :page-id updated-frames)]
|
||||
(rx/merge
|
||||
;; Emit one layout/update event for each page.
|
||||
(->> frames-by-page
|
||||
(map (fn [[page-id frames]]
|
||||
"Commit sync changes, schedule current-page auto-grow text remasure, then
|
||||
layout. Remasure heals box size only; it does not clear a stale
|
||||
:geometry-group flag. Keep per-page updated-frames layout and
|
||||
thumbnail clears."
|
||||
[file-id changes updated-frames undo-group current-page-id objects wasm?]
|
||||
(let [remasure-ids (when (and wasm? (some? current-page-id))
|
||||
(sync-auto-grow-text-ids-on-page changes current-page-id objects))
|
||||
frames-by-page (group-by :page-id updated-frames)
|
||||
;; Remasure-only layout when the current page has texts to heal but
|
||||
;; no synced frames entry (covers empty updated-frames too).
|
||||
remasure-only-layout? (and (seq remasure-ids)
|
||||
(nil? (get frames-by-page current-page-id)))]
|
||||
(rx/concat
|
||||
(rx/of (set-updating-library false)
|
||||
(ntf/hide {:tag :sync-dialog}))
|
||||
(when (seq (:redo-changes changes))
|
||||
(rx/of (dch/commit-changes changes)))
|
||||
;; Schedule remasure before layout (swap pattern: debounce ~40ms vs
|
||||
;; layout buffer ~100ms).
|
||||
(when (seq remasure-ids)
|
||||
(rx/of (dwwt/resize-wasm-text-all remasure-ids
|
||||
{:skip-component-sync? true
|
||||
:undo-group undo-group})))
|
||||
(rx/merge
|
||||
;; Per-page layout for synced frames; merge remasure ids into the
|
||||
;; current page so hug sees the post-remasure box.
|
||||
(->> frames-by-page
|
||||
(map (fn [[page-id frames]]
|
||||
(let [ids (cond-> (mapv :id frames)
|
||||
(and (= page-id current-page-id)
|
||||
(seq remasure-ids))
|
||||
(into remasure-ids))]
|
||||
(ptk/data-event :layout/update
|
||||
{:page-id page-id
|
||||
:ids (map :id frames)
|
||||
:undo-group undo-group})))
|
||||
(rx/from))
|
||||
(->> (rx/from updated-frames)
|
||||
(rx/mapcat
|
||||
(fn [shape]
|
||||
(rx/of
|
||||
(dwt/clear-thumbnail file-id (:page-id shape) (:id shape) "frame")
|
||||
(when-not (= (:frame-id shape) uuid/zero)
|
||||
(dwt/clear-thumbnail file-id (:page-id shape) (:frame-id shape) "frame")))))))))))
|
||||
:ids ids
|
||||
:undo-group undo-group}))))
|
||||
(rx/from))
|
||||
(when remasure-only-layout?
|
||||
(rx/of (ptk/data-event :layout/update
|
||||
{:page-id current-page-id
|
||||
:ids remasure-ids
|
||||
:undo-group undo-group})))
|
||||
(->> (rx/from updated-frames)
|
||||
(rx/mapcat
|
||||
(fn [shape]
|
||||
(rx/of
|
||||
(dwt/clear-thumbnail file-id (:page-id shape) (:id shape) "frame")
|
||||
(when-not (= (:frame-id shape) uuid/zero)
|
||||
(dwt/clear-thumbnail file-id (:page-id shape) (:frame-id shape) "frame"))))))))))
|
||||
|
||||
(defn- mark-library-synced
|
||||
"Tells the backend that `file-id` is synced with `library-id`. Only the
|
||||
@ -1354,9 +1395,17 @@
|
||||
|
||||
pending-ids (sync-file-pending-ids file-id changes)
|
||||
|
||||
current-page-id (:current-page-id state)
|
||||
|
||||
frontend-sync
|
||||
(sync-file-frontend-events
|
||||
file-id changes updated-frames undo-group)]
|
||||
file-id
|
||||
changes
|
||||
updated-frames
|
||||
undo-group
|
||||
current-page-id
|
||||
(dsh/lookup-page-objects state file-id current-page-id)
|
||||
(features/active-feature? state "render-wasm/v1"))]
|
||||
|
||||
(log/debug :msg "SYNC-FILE finished" :js/rchanges (log-changes
|
||||
(:redo-changes changes)
|
||||
|
||||
@ -1291,13 +1291,16 @@
|
||||
|
||||
(defn- add-geometry-undo-to-commit
|
||||
"Adds geometry undo/redo to a commit so undo restores both content and geometry.
|
||||
old-geom and final-geom are maps with :selrect :points and optionally :width :height."
|
||||
old-geom and final-geom are maps with :selrect :points and optionally :width :height.
|
||||
Uses :ignore-touched so auto-grow size from content edit is not a geometry override
|
||||
on component copies (mirrors commit-resize-text)."
|
||||
[base objects id old-geom final-geom attrs]
|
||||
(let [objects-with-old (update objects id #(merge % old-geom))
|
||||
final-shape-fn (fn [shape] (merge shape final-geom))]
|
||||
(-> base
|
||||
(pcb/with-objects objects-with-old)
|
||||
(pcb/update-shapes [id] final-shape-fn {:attrs attrs}))))
|
||||
(pcb/update-shapes [id] final-shape-fn {:attrs attrs
|
||||
:ignore-touched true}))))
|
||||
|
||||
(defn- build-finalize-commit-changes
|
||||
"Builds the commit changes for text finalization (content + geometry undo).
|
||||
@ -1436,7 +1439,9 @@
|
||||
;; Push the auto-grow geometry to WASM/app state; the commit persists it via `resize-geom`.
|
||||
;; Skipped for a no-op finalize: applying it would record an undo transaction.
|
||||
(when (and (some? resize-modifiers) (not finalize-no-op?))
|
||||
(dwm/apply-wasm-modifiers resize-modifiers {:undo-group (when new-shape? id)})))
|
||||
(dwm/apply-wasm-modifiers resize-modifiers
|
||||
{:undo-group (when new-shape? id)
|
||||
:ignore-touched true})))
|
||||
|
||||
(when finalize?
|
||||
(rx/concat
|
||||
|
||||
@ -92,7 +92,8 @@
|
||||
(watch [_ state _]
|
||||
(let [objects (dsh/lookup-page-objects state)
|
||||
shape (get objects id)
|
||||
apply-opts (or opts {})
|
||||
;; Auto-grow size is derived from content; never mark geometry overrides.
|
||||
apply-opts (assoc (or opts {}) :ignore-touched true)
|
||||
resize-stream
|
||||
(if (and (some? shape)
|
||||
(cfh/text-shape? shape)
|
||||
@ -132,7 +133,9 @@
|
||||
;; When undo-id is present, extend the current undo transaction instead of
|
||||
;; creating a new one, and commit it after the resize (single undo action).
|
||||
extend-tx? (some? undo-id)
|
||||
apply-opts (cond-> {}
|
||||
;; Auto-grow size is derived; hardcode here (debounce caller opts
|
||||
;; whitelist does not forward :ignore-touched).
|
||||
apply-opts (cond-> {:ignore-touched true}
|
||||
(some? undo-group) (assoc :undo-group undo-group)
|
||||
extend-tx? (assoc :undo-transation? false)
|
||||
skip-component-sync? (assoc :skip-component-sync? true))]
|
||||
|
||||
@ -0,0 +1,127 @@
|
||||
;; 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.data.workspace-sync-text-wasm-test
|
||||
"Regression test for #12721: after component sync with render-wasm/v1,
|
||||
auto-grow text copies must be scheduled for WASM remasure with
|
||||
:skip-component-sync? so box size heals without marking :geometry-group."
|
||||
(:require
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.logic.shapes :as cls]
|
||||
[app.common.test-helpers.components :as cthc]
|
||||
[app.common.test-helpers.compositions :as ctho]
|
||||
[app.common.test-helpers.files :as cthf]
|
||||
[app.common.test-helpers.ids-map :as cthi]
|
||||
[app.common.test-helpers.shapes :as cths]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.workspace.libraries :as dwl]
|
||||
[app.main.data.workspace.wasm-text :as dwwt]
|
||||
[beicon.v2.core :as rx]
|
||||
[cljs.test :as t :include-macros true]
|
||||
[frontend-tests.helpers.state :as ths]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
(def ^:private orig-resize-wasm-text-all dwwt/resize-wasm-text-all)
|
||||
|
||||
(def ^:private resize-calls (atom []))
|
||||
|
||||
(defn- mock-resize-wasm-text-all
|
||||
([ids] (mock-resize-wasm-text-all ids nil))
|
||||
([ids opts]
|
||||
(swap! resize-calls conj {:ids ids :opts opts})
|
||||
nil))
|
||||
|
||||
(t/use-fixtures :each
|
||||
{:before (fn []
|
||||
(cthi/reset-idmap!)
|
||||
(reset! resize-calls [])
|
||||
(set! dwwt/resize-wasm-text-all mock-resize-wasm-text-all))
|
||||
:after (fn []
|
||||
(set! dwwt/resize-wasm-text-all orig-resize-wasm-text-all))})
|
||||
|
||||
(defn- setup-file
|
||||
[& {:keys [grow-type] :or {grow-type :auto-width}}]
|
||||
(-> (cthf/sample-file :file1)
|
||||
(ctho/add-frame-with-text :main-root :main-child "hello world"
|
||||
:child-params {:grow-type grow-type})
|
||||
(cthc/make-component :component1 :main-root)
|
||||
(cthc/instantiate-component :component1 :copy-root
|
||||
{:children-labels [:copy-child]})))
|
||||
|
||||
(defn- bump-main-font-size
|
||||
[file]
|
||||
(let [page (cthf/current-page file)
|
||||
main-child (cths/get-shape file :main-child)
|
||||
changes (cls/generate-update-shapes
|
||||
(pcb/empty-changes nil (:id page))
|
||||
#{(:id main-child)}
|
||||
(fn [shape]
|
||||
(assoc-in shape
|
||||
[:content :children 0 :children 0 :children 0 :font-size]
|
||||
"32"))
|
||||
(:objects page)
|
||||
{})]
|
||||
(cthf/apply-changes file changes)))
|
||||
|
||||
(defn- collect-layout-updates
|
||||
"Subscribe before emit; accumulates deref'd `:layout/update` payloads."
|
||||
[store]
|
||||
(let [acc (atom [])]
|
||||
(->> (ptk/input-stream store)
|
||||
(rx/filter (ptk/type? :layout/update))
|
||||
(rx/tap #(swap! acc conj (deref %)))
|
||||
(rx/subs! (fn [_] nil)))
|
||||
acc))
|
||||
|
||||
(t/deftest test-sync-file-schedules-wasm-text-remasure
|
||||
(t/async
|
||||
done
|
||||
(let [file (-> (setup-file) bump-main-font-size)
|
||||
store (ths/setup-store file)
|
||||
page-id (cthf/current-page-id file)
|
||||
copy-id (:id (cths/get-shape file :copy-child))
|
||||
undo-group (uuid/next)
|
||||
layout-updates (collect-layout-updates store)
|
||||
|
||||
events
|
||||
[(dwl/sync-file (:id file) (:id file)
|
||||
:components (cthi/id :component1)
|
||||
undo-group)]]
|
||||
|
||||
(ths/run-store
|
||||
store done events
|
||||
(fn [_new-state]
|
||||
(t/is (= 1 (count @resize-calls))
|
||||
"resize-wasm-text-all should run once after sync")
|
||||
(let [{:keys [ids opts]} (first @resize-calls)
|
||||
layout-ids (->> @layout-updates
|
||||
(filter #(= page-id (:page-id %)))
|
||||
(mapcat :ids)
|
||||
set)]
|
||||
(t/is (some #{copy-id} ids)
|
||||
"remasure ids should include the copy text")
|
||||
(t/is (:skip-component-sync? opts)
|
||||
"remasure must use :skip-component-sync? so size heal does not mark :geometry-group")
|
||||
(t/is (= undo-group (:undo-group opts)))
|
||||
(t/is (every? layout-ids ids)
|
||||
(str "current-page :layout/update ids must include remasure ids; "
|
||||
"layout=" layout-ids " remasure=" ids))))))))
|
||||
|
||||
(t/deftest test-sync-file-skips-remasure-for-fixed-text
|
||||
(t/async
|
||||
done
|
||||
(let [file (-> (setup-file :grow-type :fixed) bump-main-font-size)
|
||||
store (ths/setup-store file)
|
||||
|
||||
events
|
||||
[(dwl/sync-file (:id file) (:id file)
|
||||
:components (cthi/id :component1))]]
|
||||
|
||||
(ths/run-store
|
||||
store done events
|
||||
(fn [_new-state]
|
||||
(t/is (empty? @resize-calls)
|
||||
"fixed-grow texts must not be scheduled for WASM remasure"))))))
|
||||
@ -7,7 +7,10 @@
|
||||
(ns frontend-tests.data.workspace-texts-test
|
||||
(:require
|
||||
[app.common.geom.rect :as grc]
|
||||
[app.common.test-helpers.components :as cthc]
|
||||
[app.common.test-helpers.compositions :as ctho]
|
||||
[app.common.test-helpers.files :as cthf]
|
||||
[app.common.test-helpers.ids-map :as cthi]
|
||||
[app.common.test-helpers.shapes :as cths]
|
||||
[app.common.types.modifiers :as ctm]
|
||||
[app.common.types.shape :as cts]
|
||||
@ -19,8 +22,16 @@
|
||||
[beicon.v2.core :as rx]
|
||||
[cljs.test :as t :include-macros true]
|
||||
[frontend-tests.helpers.state :as ths]
|
||||
[frontend-tests.helpers.wasm :as thw]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
(t/use-fixtures :each
|
||||
{:before (fn []
|
||||
(cthi/reset-idmap!)
|
||||
(thw/setup-wasm-mocks!))
|
||||
:after (fn []
|
||||
(thw/teardown-wasm-mocks!))})
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; Helpers
|
||||
;; ---------------------------------------------------------------------------
|
||||
@ -313,6 +324,39 @@
|
||||
(= :app.main.data.workspace.shapes/update-shapes (ptk/type %)))
|
||||
@events))))
|
||||
|
||||
;; Scenario: finalize an auto-grow text edit on a component copy under
|
||||
;; render-wasm/v1. Proves: content is committed and the auto-resize does
|
||||
;; not mark :geometry-group (so later main font-size sync can still size
|
||||
;; the box). See #12721.
|
||||
(t/deftest finalize-auto-grow-copy-skips-geometry-touched
|
||||
(t/async
|
||||
done
|
||||
(let [file (-> (cthf/sample-file :file1)
|
||||
(ctho/add-frame-with-text :main-root :main-child "hello world")
|
||||
(cthc/make-component :component1 :main-root)
|
||||
(cthc/instantiate-component :component1 :copy-root
|
||||
{:children-labels [:copy-child]}))
|
||||
copy (cths/get-shape file :copy-child)
|
||||
copy-id (:id copy)
|
||||
store (ths/setup-store file)
|
||||
mid (txt/change-text (:content copy) "typing")
|
||||
final (txt/change-text (:content copy) "changed")
|
||||
;; Non-finalize first so session geom is stored; otherwise finalize
|
||||
;; is treated as a no-op and skips the geometry commit path.
|
||||
events [(dwt/v2-update-text-shape-content copy-id mid :finalize? false)
|
||||
(dwt/v2-update-text-shape-content copy-id final :finalize? true)]]
|
||||
|
||||
(ths/run-store
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-state new-state)
|
||||
copy' (cths/get-shape file' :copy-child)
|
||||
text' (get-in copy' [:content :children 0 :children 0 :children 0 :text])]
|
||||
(t/is (= "changed" text')
|
||||
"finalize must commit the edited content")
|
||||
(t/is (not (contains? (:touched copy') :geometry-group))
|
||||
"auto-grow finalize must not mark :geometry-group on a component copy")))))))
|
||||
|
||||
(t/deftest add-typography-normalises-float-line-height
|
||||
(t/async
|
||||
done
|
||||
|
||||
@ -51,6 +51,7 @@
|
||||
[frontend-tests.data.workspace-path-edition-test]
|
||||
[frontend-tests.data.workspace-reflow-test]
|
||||
[frontend-tests.data.workspace-shortcuts-test]
|
||||
[frontend-tests.data.workspace-sync-text-wasm-test]
|
||||
[frontend-tests.data.workspace-texts-test]
|
||||
[frontend-tests.data.workspace-thumbnails-test]
|
||||
[frontend-tests.data.workspace-undo-test]
|
||||
@ -262,6 +263,7 @@
|
||||
'frontend-tests.data.workspace-path-edition-test
|
||||
'frontend-tests.data.workspace-reflow-test
|
||||
'frontend-tests.data.workspace-shortcuts-test
|
||||
'frontend-tests.data.workspace-sync-text-wasm-test
|
||||
'frontend-tests.data.workspace-texts-test
|
||||
'frontend-tests.data.workspace-thumbnails-test
|
||||
'frontend-tests.data.workspace-undo-test
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user