mirror of
https://github.com/penpot/penpot.git
synced 2025-05-18 18:46:10 +02:00
✨ Improved text selection
This commit is contained in:
parent
618d22d214
commit
bbf91a8957
6 changed files with 82 additions and 27 deletions
|
@ -82,7 +82,7 @@
|
|||
|
||||
(defn add-fill
|
||||
([attrs shape render-id]
|
||||
(add-fill attrs shape render-id 0))
|
||||
(add-fill attrs shape render-id nil))
|
||||
|
||||
([attrs shape render-id index]
|
||||
(let [fill-attrs
|
||||
|
@ -92,7 +92,7 @@
|
|||
{:fill (str/format "url(#%s)" fill-image-id)})
|
||||
|
||||
(contains? shape :fill-color-gradient)
|
||||
(let [fill-color-gradient-id (str "fill-color-gradient_" render-id "_" index)]
|
||||
(let [fill-color-gradient-id (str "fill-color-gradient_" render-id (if index (str "_" index) ""))]
|
||||
{:fill (str/format "url(#%s)" fill-color-gradient-id)})
|
||||
|
||||
(contains? shape :fill-color)
|
||||
|
|
|
@ -98,16 +98,6 @@
|
|||
(some #(cph/is-parent? objects % group-id))
|
||||
(not))))
|
||||
|
||||
(defn check-text-collision?
|
||||
"Checks if he current position `pos` overlaps any of the text-nodes for the given `text-id`"
|
||||
[objects pos text-id]
|
||||
(and (= :text (get-in objects [text-id :type]))
|
||||
(let [collisions
|
||||
(->> (dom/query-all (str "#shape-" text-id " .text-node"))
|
||||
(map dom/get-bounding-rect)
|
||||
(map dom/bounding-rect->rect))]
|
||||
(not (some #(gshr/contains-point? % pos) collisions)))))
|
||||
|
||||
(defn setup-hover-shapes [page-id move-stream raw-position-ref objects transform selected ctrl? hover hover-ids hover-disabled? zoom]
|
||||
(let [;; We use ref so we don't recreate the stream on a change
|
||||
zoom-ref (mf/use-ref zoom)
|
||||
|
@ -180,9 +170,6 @@
|
|||
|
||||
remove-xfm (mapcat #(cph/get-parent-ids objects %))
|
||||
remove-id? (cond-> (into #{} remove-xfm selected)
|
||||
:always
|
||||
(into (filter #(check-text-collision? objects (mf/ref-val raw-position-ref) %)) ids)
|
||||
|
||||
(not @ctrl?)
|
||||
(into (filter #(group-empty-space? % objects ids)) ids)
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.geom.shapes.text :as gte]
|
||||
[app.common.pages :as cp]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.uuid :as uuid]
|
||||
|
@ -23,7 +24,15 @@
|
|||
(defn index-shape
|
||||
[objects parents-index clip-parents-index]
|
||||
(fn [index shape]
|
||||
(let [{:keys [x y width height]} (gsh/points->selrect (:points shape))
|
||||
(let [{:keys [x y width height]}
|
||||
(cond
|
||||
(and (= :text (:type shape))
|
||||
(some? (:position-data shape))
|
||||
(d/not-empty? (:position-data shape)))
|
||||
(gte/position-data-bounding-box shape)
|
||||
|
||||
:else
|
||||
(gsh/points->selrect (:points shape)))
|
||||
shape-bound #js {:x x :y y :width width :height height}
|
||||
|
||||
parents (get parents-index (:id shape))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue