Skip to content

Commit

Permalink
fix: disallow cutting blocks when find in page
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Aug 24, 2022
1 parent b677d6f commit fac1180
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/electron/listener.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
(js/window.apis.on "foundInPage"
(fn [data]
(let [data' (bean/->clj data)]
(state/set-state! [:ui/find-in-search :matches] data')
(state/set-state! [:ui/find-in-page :matches] data')
true)))

(js/window.apis.on "loginCallback"
Expand Down
10 changes: 5 additions & 5 deletions src/main/frontend/components/find_in_page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
(when (and (= (.-code e) "Enter")
(not (state/editing?)))
(let [shift? (.-shiftKey e)]
(state/set-state! [:ui/find-in-search :backward?] shift?)
(state/set-state! [:ui/find-in-page :backward?] shift?)
(search-handler/electron-find-in-page!))))

(rum/defc search-inner <
Expand All @@ -50,7 +50,7 @@
:placeholder "Find in page"
:on-change (fn [e]
(let [value (util/evalue e)]
(state/set-state! [:ui/find-in-search :q] value)
(state/set-state! [:ui/find-in-page :q] value)
(if (string/blank? value)
(search-handler/electron-exit-find-in-page!)
(debounced-search))))}]]
Expand All @@ -62,15 +62,15 @@
(ui/button
(ui/icon "caret-up" {:style {:font-size 18}})
:on-click (fn []
(state/set-state! [:ui/find-in-search :backward?] true)
(state/set-state! [:ui/find-in-page :backward?] true)
(search-handler/electron-find-in-page!))
:intent "link"
:small? true)

(ui/button
(ui/icon "caret-down" {:style {:font-size 18}})
:on-click (fn []
(state/set-state! [:ui/find-in-search :backward?] false)
(state/set-state! [:ui/find-in-page :backward?] false)
(search-handler/electron-find-in-page!))
:intent "link"
:small? true)
Expand All @@ -84,6 +84,6 @@

(rum/defc search < rum/reactive
[]
(let [{:keys [active?] :as opt} (state/sub :ui/find-in-search)]
(let [{:keys [active?] :as opt} (state/sub :ui/find-in-page)]
(when active?
(search-inner opt))))
5 changes: 3 additions & 2 deletions src/main/frontend/handler/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2907,8 +2907,9 @@

(defn- cut-blocks-and-clear-selections!
[copy?]
(cut-selection-blocks copy?)
(clear-selection!))
(when-not (get-in @state/state [:ui/find-in-page :active?])
(cut-selection-blocks copy?)
(clear-selection!)))

(defn shortcut-copy-selection
[_e]
Expand Down
6 changes: 3 additions & 3 deletions src/main/frontend/handler/search.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
(electron-find-in-page! nil))
([on-success]
(when (util/electron?)
(let [{:keys [active? backward? q]} (:ui/find-in-search @state/state)
(let [{:keys [active? backward? q]} (:ui/find-in-page @state/state)
option (cond->
{}

Expand All @@ -63,7 +63,7 @@

backward?
(assoc :forward false))]
(when-not active? (state/set-state! [:ui/find-in-search :active?] true))
(when-not active? (state/set-state! [:ui/find-in-page :active?] true))
(when-not (string/blank? q)
(ipc/ipc "find-in-page" q option)
(when on-success
Expand All @@ -75,7 +75,7 @@
(when (util/electron?)
(ipc/ipc "clear-find-in-page")
(when clear-state?
(state/set-state! :ui/find-in-search nil))))
(state/set-state! :ui/find-in-page nil))))

(defn clear-search!
([]
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/state.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@

:encryption/graph-parsing? false

:ui/find-in-search nil
:ui/find-in-page nil
})))

;; block uuid -> {content(String) -> ast}
Expand Down

0 comments on commit fac1180

Please sign in to comment.