diff --git a/frontend/src/app/main/ui/workspace/shapes/text/v2_editor.cljs b/frontend/src/app/main/ui/workspace/shapes/text/v2_editor.cljs index 525b1d0613..e81f841baf 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text/v2_editor.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text/v2_editor.cljs @@ -367,6 +367,9 @@ (when (cf/check-browser? :safari) (mf/deref refs/selected-zoom)) + vbox + (mf/deref refs/vbox) + shape (cond-> shape (some? text-modifier) (dwt/apply-text-modifier text-modifier) @@ -385,13 +388,20 @@ selrect-width (:width selrect) max-width (max width selrect-width) max-height (max height selrect-height) + ;; During auto-width editing we keep the shape width trimmed, but the caret + ;; must be able to move after trailing spaces. Expand only the editor + ;; overlay up to one viewport width to avoid clipping caret rendering. + viewport-width (or (:width vbox) 0) + overlay-width (if (= (:grow-type shape) :auto-width) + (+ max-width viewport-width) + max-width) valign (-> shape :content :vertical-align) y (:y selrect) y (case valign "bottom" (+ y (- selrect-height height)) "center" (+ y (/ (- selrect-height height) 2)) y)] - [(assoc selrect :y y :width max-width :height max-height) transform]) + [(assoc selrect :y y :width overlay-width :height max-height) transform]) (let [bounds (gst/shape->rect shape) x (mth/min (dm/get-prop bounds :x) diff --git a/frontend/src/app/main/ui/workspace/shapes/text/v2_editor.scss b/frontend/src/app/main/ui/workspace/shapes/text/v2_editor.scss index 642a4cabf3..d31fa44ef0 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text/v2_editor.scss +++ b/frontend/src/app/main/ui/workspace/shapes/text/v2_editor.scss @@ -53,7 +53,10 @@ font-size: 0px; } - [data-itype="inline"] { + // Text spans emitted by @penpot/text-editor use `data-itype="span"`. + // Keep whitespace rules attached to the real node type so trailing spaces + // are handled consistently while editing. + [data-itype="span"] { box-sizing: content-box; display: inline; line-height: inherit; @@ -75,11 +78,11 @@ .grow-type-auto-width { [data-itype="span"], [data-itype="paragraph"] { - white-space: nowrap; - } - - [data-itype="span"] { - white-space-collapse: preserve; + // Keep auto-width editing on a single preformatted line so trailing + // spaces are part of caret geometry and browser selection math. + white-space: pre; + overflow-wrap: normal; + word-break: keep-all; } }