From 35eb57c402963ee97bdf1d0796fc60e407015f78 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Fri, 17 Nov 2023 13:42:58 +0800 Subject: [PATCH] enhance: close modal when ESC and input hasn't been changed --- src/main/frontend/components/cmdk.cljs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/frontend/components/cmdk.cljs b/src/main/frontend/components/cmdk.cljs index bf928fe102..4cf7f6fa2c 100644 --- a/src/main/frontend/components/cmdk.cljs +++ b/src/main/frontend/components/cmdk.cljs @@ -530,6 +530,8 @@ ;; update the input value in the UI (reset! !input input) + (reset! (::input-changed? state) true) + ;; ensure that there is a throttled version of the load-results function (when-not @!load-results-throttled (reset! !load-results-throttled (gfun/throttle load-results 50))) @@ -576,7 +578,8 @@ (handle-action :default state e) (util/stop-propagation e)) esc? (let [filter @(::filter state)] - (when (or filter (not (string/blank? input))) + (when (or (and filter @(::input-changed? state)) + (not (string/blank? input))) (util/stop e) (reset! (::filter state) nil) (when-not filter (handle-input-change state nil "")))) @@ -775,6 +778,7 @@ (rum/local nil ::load-results-throttled) (rum/local nil ::scroll-container-ref) (rum/local nil ::input-ref) + (rum/local false ::input-changed?) [state {:keys [sidebar?] :as opts}] (let [*input (::input state) _input (rum/react *input)