mirror of
https://github.com/penpot/penpot.git
synced 2026-09-11 06:28:47 +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)
|
text-match-count (count text-match-ids)
|
||||||
safe-match-idx (if (pos? text-match-count) (mod current-match-idx text-match-count) 0)
|
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
|
navigate-next
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps text-match-count)
|
(mf/deps text-match-count)
|
||||||
(fn [_]
|
(fn [_]
|
||||||
(when (pos? text-match-count)
|
(when (pos? text-match-count)
|
||||||
(swap! state* update :current-match-idx
|
(let [ids (mf/ref-val text-match-ids-ref)
|
||||||
(fn [idx]
|
next-idx (mod (inc (mf/ref-val match-idx-ref)) text-match-count)
|
||||||
(mod (inc idx) 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
|
navigate-prev
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps text-match-count)
|
(mf/deps text-match-count)
|
||||||
(fn [_]
|
(fn [_]
|
||||||
(when (pos? text-match-count)
|
(when (pos? text-match-count)
|
||||||
(swap! state* update :current-match-idx
|
(let [ids (mf/ref-val text-match-ids-ref)
|
||||||
(fn [idx]
|
prev-idx (mod (+ (dec (mf/ref-val match-idx-ref)) text-match-count) text-match-count)
|
||||||
(mod (+ (dec idx) 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
|
handle-replace
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user