fix: gracefully handle invalid jump

invalid selection was resulting in errors and jumps persisting
in weird ways
pull/11049/merge
Gabriel Horner 2024-03-12 10:22:35 -04:00
parent 636f9554ab
commit 778f2c1688
1 changed files with 13 additions and 10 deletions

View File

@ -3,7 +3,8 @@
(:require [frontend.state :as state]
[dommy.core :as d]
[clojure.string :as string]
[frontend.util :as util]))
[frontend.util :as util]
[frontend.handler.notification :as notification]))
(defonce *current-keys (atom nil))
(defonce *jump-data (atom {}))
@ -62,17 +63,19 @@
(defn get-trigger
[triggers key]
(when-let [idx (.indexOf @*current-keys key)]
(nth triggers idx)))
(let [idx (.indexOf @*current-keys key)]
(when (>= idx 0) (nth triggers idx))))
(defn trigger!
[key e]
(let [{:keys [triggers _mode]} @*jump-data]
(when-let [trigger (get-trigger triggers (string/trim key))]
(let [trigger (get-trigger triggers (string/trim key))]
(util/stop e)
(state/clear-selection!)
(exit!)
(.click trigger))))
(if trigger
(.click trigger)
(notification/show! "Invalid jump" :error true)))))
(defn jump-to
[]