mirror of
https://github.com/penpot/penpot.git
synced 2026-07-25 07:28:22 +00:00
🐛 Center canvas and select layer when navigating search results (#10453)
Co-authored-by: Andrey Antukh <niwi@niwi.nz>
This commit is contained in:
parent
3fa7943344
commit
6e85ce5d7a
@ -431,23 +431,36 @@
|
||||
text-match-count (count text-match-ids)
|
||||
safe-match-idx (if (pos? text-match-count) (mod current-match-idx text-match-count) 0)
|
||||
|
||||
text-match-ids-ref (mf/use-ref text-match-ids)
|
||||
match-idx-ref (mf/use-ref 0)
|
||||
|
||||
_ (mf/set-ref-val! text-match-ids-ref text-match-ids)
|
||||
|
||||
navigate-next
|
||||
(mf/use-fn
|
||||
(mf/deps text-match-count)
|
||||
(fn [_]
|
||||
(when (pos? text-match-count)
|
||||
(swap! state* update :current-match-idx
|
||||
(fn [idx]
|
||||
(mod (inc idx) text-match-count))))))
|
||||
(let [ids (mf/ref-val text-match-ids-ref)
|
||||
next-idx (mod (inc (mf/ref-val match-idx-ref)) text-match-count)
|
||||
id (nth ids next-idx)]
|
||||
(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)))))
|
||||
|
||||
navigate-prev
|
||||
(mf/use-fn
|
||||
(mf/deps text-match-count)
|
||||
(fn [_]
|
||||
(when (pos? text-match-count)
|
||||
(swap! state* update :current-match-idx
|
||||
(fn [idx]
|
||||
(mod (+ (dec idx) text-match-count) text-match-count))))))
|
||||
(let [ids (mf/ref-val text-match-ids-ref)
|
||||
prev-idx (mod (+ (dec (mf/ref-val match-idx-ref)) text-match-count) text-match-count)
|
||||
id (nth ids prev-idx)]
|
||||
(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)))))
|
||||
|
||||
handle-replace
|
||||
(mf/use-fn
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user