fix: search/editor frozen by base64 encoded image

pull/5355/head^2
Tienson Qin 2022-08-23 17:49:45 +08:00
parent c7703e5e93
commit bdbf4bad2a
4 changed files with 66 additions and 57 deletions

View File

@ -1967,55 +1967,56 @@
(dom/closest target ".query-table")))
(defn- block-content-on-mouse-down
[e block block-id _content edit-input-id]
(.stopPropagation e)
(let [target (gobj/get e "target")
button (gobj/get e "buttons")
shift? (gobj/get e "shiftKey")
meta? (util/meta-key? e)]
(if (and meta? (not (state/get-edit-input-id)))
(do
(util/stop e)
(state/conj-selection-block! (gdom/getElement block-id) :down)
(when (and block-id (not (state/get-selection-start-block)))
(state/set-selection-start-block! block-id)))
(when (contains? #{1 0} button)
(when-not (target-forbidden-edit? target)
(cond
(and shift? (state/get-selection-start-block-or-first))
(do
(util/stop e)
[e block block-id content edit-input-id]
(when-not (util/base64-image-included? content)
(.stopPropagation e)
(let [target (gobj/get e "target")
button (gobj/get e "buttons")
shift? (gobj/get e "shiftKey")
meta? (util/meta-key? e)]
(if (and meta? (not (state/get-edit-input-id)))
(do
(util/stop e)
(state/conj-selection-block! (gdom/getElement block-id) :down)
(when (and block-id (not (state/get-selection-start-block)))
(state/set-selection-start-block! block-id)))
(when (contains? #{1 0} button)
(when-not (target-forbidden-edit? target)
(cond
(and shift? (state/get-selection-start-block-or-first))
(do
(util/stop e)
(util/clear-selection!)
(editor-handler/highlight-selection-area! block-id))
shift?
(util/clear-selection!)
(editor-handler/highlight-selection-area! block-id))
shift?
(util/clear-selection!)
:else
(do
(editor-handler/clear-selection!)
(editor-handler/unhighlight-blocks!)
(let [f #(let [block (or (db/pull [:block/uuid (:block/uuid block)]) block)
cursor-range (util/caret-range (gdom/getElement block-id))
{:block/keys [content format]} block
content (->> content
(property/remove-built-in-properties format)
(drawer/remove-logbook))]
;; save current editing block
(let [{:keys [value] :as state} (editor-handler/get-state)]
(editor-handler/save-block! state value))
(state/set-editing!
edit-input-id
content
block
cursor-range
false))]
;; wait a while for the value of the caret range
(if (util/ios?)
(f)
(js/setTimeout f 5))
:else
(do
(editor-handler/clear-selection!)
(editor-handler/unhighlight-blocks!)
(let [f #(let [block (or (db/pull [:block/uuid (:block/uuid block)]) block)
cursor-range (util/caret-range (gdom/getElement block-id))
{:block/keys [content format]} block
content (->> content
(property/remove-built-in-properties format)
(drawer/remove-logbook))]
;; save current editing block
(let [{:keys [value] :as state} (editor-handler/get-state)]
(editor-handler/save-block! state value))
(state/set-editing!
edit-input-id
content
block
cursor-range
false))]
;; wait a while for the value of the caret range
(if (util/ios?)
(f)
(js/setTimeout f 5))
(when block-id (state/set-selection-start-block! block-id))))))))))
(when block-id (state/set-selection-start-block! block-id)))))))))))
(rum/defc dnd-separator-wrapper < rum/reactive
[block block-id slide? top? block-content?]

View File

@ -14,10 +14,11 @@
"Convert a block to the index for searching"
[{:block/keys [uuid page content] :as block}]
(when-let [content (util/search-normalize content (state/enable-search-remove-accents?))]
{:id (:db/id block)
:uuid (str uuid)
:page page
:content content}))
(when-not (util/base64-image-included? content)
{:id (:db/id block)
:uuid (str uuid)
:page page
:content content})))
(defn build-blocks-indice
;; TODO: Remove repo effects fns further up the call stack. db fns need standardization on taking connection

View File

@ -3,20 +3,22 @@
[electron.ipc :as ipc]
[frontend.search.db :as search-db]
[frontend.search.protocol :as protocol]
[promesa.core :as p]))
[promesa.core :as p]
[frontend.util :as util]))
(defrecord Node [repo]
protocol/Engine
(query [_this q opts]
(p/let [result (ipc/ipc "search-blocks" repo q opts)
result (bean/->clj result)]
(map (fn [{:keys [content uuid page]}]
{:block/uuid uuid
:block/content content
:block/page page}) result)))
(keep (fn [{:keys [content uuid page]}]
(when-not (util/base64-image-included? content)
{:block/uuid uuid
:block/content content
:block/page page})) result)))
(cache-stale? [_this repo]
;; only FTS require cache validating
(ipc/ipc "searchVersionChanged?" repo))
;; only FTS require cache validating
(ipc/ipc "searchVersionChanged?" repo))
(rebuild-blocks-indice! [_this]
(let [indice (search-db/build-blocks-indice repo)]
(ipc/ipc "rebuild-blocks-indice" repo indice)))

View File

@ -1343,3 +1343,8 @@
Math/floor
int
(#(str % " " (:name unit) (when (> % 1) "s") " ago"))))))))
#?(:cljs
(defn base64-image-included?
[content]
(string/includes? content "data:image/png;base64,")))