From eacd656201a363b83a8a44d124e4944f7f3b0d3f Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 26 Nov 2026 16:30:34 +0100 Subject: [PATCH] :bug: Keep the text selection toolbar inside the canvas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The toolbar opens to the right of the selection, so near the right edge of the canvas it was cut off and its last button showed as "Co…". It is now measured before paint and moved left by what overflows, without passing the left edge. AI-assisted-by: claude-opus-5-5 --- .../workspace/shapes/text/selection_menu.cljs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/main/ui/workspace/shapes/text/selection_menu.cljs b/frontend/src/app/main/ui/workspace/shapes/text/selection_menu.cljs index d268389f08..fe151b73f9 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text/selection_menu.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text/selection_menu.cljs @@ -122,6 +122,21 @@ ;; shows below it. (def ^:private icon-room 40) +;; Space kept between the toolbar and the right edge of the viewport. +(def ^:private edge-room 8) + +(defn- keep-inside-viewport + "Moves the toolbar `node` left as far as it runs past the right edge of a + viewport `viewport-width` wide, from its anchor at `left`, but never past + the left edge." + [^js node left viewport-width] + (dom/unset-css-property! node "translate") + (let [start (+ left (.-offsetLeft node)) + overflow (- (+ start (.-offsetWidth node) edge-room) viewport-width) + shift (min overflow start)] + (when (pos? shift) + (dom/set-css-property! node "translate" (dm/str "-" shift "px 0"))))) + (mf/defc menu-item* "Button with `children` as its icon, before the label, and a caret after it when it opens a dropdown, open when `expanded` is true. `active` shows @@ -387,6 +402,7 @@ more-open* (mf/use-state false) more-open (deref more-open*) timer-ref (mf/use-ref nil) + menu-ref (mf/use-ref nil) engaged? (or (= view :ruby) emphasis-open) open? (or expanded? engaged?) @@ -395,6 +411,7 @@ top (* (- (:y rect) (:y vbox)) zoom) bottom (* (- (+ (:y rect) (:height rect)) (:y vbox)) zoom) below? (< top icon-room) + viewport-width (* (:width vbox) zoom) style (mf/with-memo [right top bottom below?] #js {:left (dm/str right "px") :top (dm/str (if below? bottom top) "px")}) @@ -453,6 +470,11 @@ (mf/with-effect [cancel-collapse] cancel-collapse) + ;; Before paint, so the toolbar never shows cut at the edge. + (mf/with-layout-effect [open? view more-open emphasis-open right viewport-width] + (when-let [node (mf/ref-val menu-ref)] + (keep-inside-viewport node right viewport-width))) + [:div {:class (stl/css-case :selection-anchor true :selection-anchor-below below?) :style style @@ -463,7 +485,8 @@ :on-pointer-enter expand :on-pointer-leave schedule-collapse} (if ^boolean open? - [:div {:class (stl/css-case :selection-menu true + [:div {:ref menu-ref + :class (stl/css-case :selection-menu true :ruby-view (= view :ruby)) :role "toolbar" :aria-label (tr "workspace.text-selection-menu.title")}