🐛 Center canvas and select layer when navigating layer search results (#10422) (#11391)

When using previous/next buttons in the layer search panel, the canvas
now centers on the matched layer and selects it in the layers panel.
Previously only the internal search cursor was advanced without any
visible canvas or selection update.

Co-authored-by: Sumit Ridhal <sridhal@redhat.com>
This commit is contained in:
Andrey Antukh
2026-08-27 18:33:48 +02:00
committed by GitHub
parent 11224940ab
commit 1baa8bb29f
3 changed files with 31 additions and 4 deletions
@@ -1698,6 +1698,7 @@
(dm/export dwgu/set-hover-guide)
;; Zoom
(dm/export dwz/center-on-shape)
(dm/export dwz/reset-zoom)
(dm/export dwz/zoom-to-selected-shape)
(dm/export dwz/start-zooming)
@@ -135,6 +135,32 @@
(effect [_ state _]
(dwvw/maybe-sync-workspace-local-viewport! state))))
(defn center-on-shape
"Pan the viewport to center on the shape with the given id without changing zoom."
[id]
(ptk/reify ::center-on-shape
ptk/UpdateEvent
(update [_ state]
(if (dwvw/render-context-lost? state)
state
(let [page-id (:current-page-id state)
objects (dsh/lookup-page-objects state page-id)
shape (get objects id)
srect (:selrect shape)]
(if (nil? srect)
state
(update state :workspace-local
(fn [{:keys [vbox] :as local}]
(let [cx (+ (:x srect) (/ (:width srect) 2))
cy (+ (:y srect) (/ (:height srect) 2))
new-x (- cx (/ (:width vbox) 2))
new-y (- cy (/ (:height vbox) 2))]
(update local :vbox assoc :x new-x :y new-y))))))))
ptk/EffectEvent
(effect [_ state _]
(dwvw/maybe-sync-workspace-local-viewport! state))))
(def zoom-to-selected-shape
(ptk/reify ::zoom-to-selected-shape
ptk/UpdateEvent
@@ -438,7 +438,7 @@
navigate-next
(mf/use-fn
(mf/deps text-match-count)
(mf/deps text-match-ids text-match-count)
(fn [_]
(when (pos? text-match-count)
(let [ids (mf/ref-val text-match-ids-ref)
@@ -447,11 +447,11 @@
(mf/set-ref-val! match-idx-ref next-idx)
(swap! state* assoc :current-match-idx next-idx)
(st/emit! (dw/select-shape id)
dw/zoom-to-selected-shape)))))
(dw/center-on-shape id))))))
navigate-prev
(mf/use-fn
(mf/deps text-match-count)
(mf/deps text-match-ids text-match-count)
(fn [_]
(when (pos? text-match-count)
(let [ids (mf/ref-val text-match-ids-ref)
@@ -460,7 +460,7 @@
(mf/set-ref-val! match-idx-ref prev-idx)
(swap! state* assoc :current-match-idx prev-idx)
(st/emit! (dw/select-shape id)
dw/zoom-to-selected-shape)))))
(dw/center-on-shape id))))))
handle-replace
(mf/use-fn