mirror of
https://github.com/penpot/penpot.git
synced 2026-04-25 11:18:36 +00:00
🐛 Fix embedded editor pasting text
This commit is contained in:
parent
d2422e3a21
commit
6b409d8d92
@ -25,6 +25,7 @@
|
||||
[app.main.data.workspace.edition :as dwe]
|
||||
[app.main.data.workspace.selection :as dws]
|
||||
[app.main.data.workspace.undo :as dwu]
|
||||
[app.main.store :as st]
|
||||
[beicon.v2.core :as rx]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
@ -50,7 +51,7 @@
|
||||
([ids update-fn] (update-shapes ids update-fn nil))
|
||||
([ids update-fn
|
||||
{:keys [reg-objects? save-undo? stack-undo? attrs ignore-tree page-id
|
||||
ignore-touched undo-group with-objects? changed-sub-attr]
|
||||
ignore-touched undo-group with-objects? changed-sub-attr ignore-wasm?]
|
||||
:or {reg-objects? false
|
||||
save-undo? true
|
||||
stack-undo? false
|
||||
@ -97,7 +98,9 @@
|
||||
|
||||
(rx/concat
|
||||
(if (seq (:redo-changes changes))
|
||||
(let [changes (cond-> changes reg-objects? (pcb/resize-parents ids))]
|
||||
(let [changes (cond-> changes
|
||||
reg-objects? (pcb/resize-parents ids)
|
||||
ignore-wasm? (assoc :ignore-wasm? true))]
|
||||
(rx/of (dch/commit-changes changes)))
|
||||
(rx/empty))
|
||||
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
;; 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 INC
|
||||
|
||||
(ns app.main.data.workspace.text-selrect-callback
|
||||
"Event to update text shape selrect from WASM dimensions.
|
||||
Lives here so app.render-wasm.api can emit it without requiring shapes
|
||||
(which would create a circular dependency: shapes -> changes -> render-wasm)."
|
||||
(:require
|
||||
[app.common.geom.matrix :as gmt]
|
||||
[app.common.geom.rect :as grc]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.main.data.helpers :as dsh]
|
||||
[app.main.store :as st]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
(defn update-text-shape-selrect
|
||||
"Updates a text shape's selrect in the main store from WASM-computed dimensions.
|
||||
Used when pasting text (no text shape selected) so the selection rect matches
|
||||
the actual rendered text bounds. Emitted by app.render-wasm.api."
|
||||
[shape-id dimensions]
|
||||
(ptk/reify ::update-text-shape-selrect
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [file-id (:current-file-id state)
|
||||
page-id (:current-page-id state)
|
||||
objects (dsh/lookup-page-objects state file-id page-id)
|
||||
shape (get objects shape-id)]
|
||||
(if (and shape dimensions (:width dimensions) (:height dimensions))
|
||||
(let [center (gsh/shape->center shape)
|
||||
transform (:transform shape (gmt/matrix))
|
||||
rect (-> (grc/make-rect dimensions)
|
||||
(grc/rect->points))
|
||||
points (gsh/transform-points rect center transform)
|
||||
selrect (gsh/calculate-selrect points (gsh/points->center points))
|
||||
path [:files file-id :data :pages-index page-id :objects shape-id]]
|
||||
(update-in state path assoc
|
||||
:selrect selrect
|
||||
:points points
|
||||
:position-data nil))
|
||||
state)))))
|
||||
@ -22,6 +22,7 @@
|
||||
[app.common.types.text :as txt]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.config :as cf]
|
||||
[app.main.data.workspace.text-selrect-callback :as text-selrect-cb]
|
||||
[app.main.refs :as refs]
|
||||
[app.main.render :as render]
|
||||
[app.main.store :as st]
|
||||
@ -993,11 +994,16 @@
|
||||
(defn update-text-rect!
|
||||
[id]
|
||||
(when wasm/context-initialized?
|
||||
(mw/emit!
|
||||
{:cmd :index/update-text-rect
|
||||
:page-id (:current-page-id @st/state)
|
||||
:shape-id id
|
||||
:dimensions (get-text-dimensions id)})))
|
||||
(let [dimensions (get-text-dimensions id)]
|
||||
(mw/emit!
|
||||
{:cmd :index/update-text-rect
|
||||
:page-id (:current-page-id @st/state)
|
||||
:shape-id id
|
||||
:dimensions dimensions})
|
||||
;; Also update the main store so the selrect is correct when pasting text
|
||||
;; (no text shape selected). Event lives in text-selrect-callback to avoid
|
||||
;; circular dependency (shapes -> changes -> render-wasm).
|
||||
(st/emit! (text-selrect-cb/update-text-shape-selrect id dimensions)))))
|
||||
|
||||
(defn- ensure-text-content
|
||||
"Guarantee that the shape always sends a valid text tree to WASM. When the
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user