From f919dac54bd0fb2b70ab708f50f69cab1eeea3c4 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Wed, 19 Jul 2023 17:53:14 +0800 Subject: [PATCH] fix: disable plain-text properties and :: to trigger property editing --- src/main/frontend/components/block.cljs | 111 ++++++++++--------- src/main/frontend/handler/editor.cljs | 14 ++- src/main/frontend/modules/outliner/core.cljs | 5 +- 3 files changed, 71 insertions(+), 59 deletions(-) diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index c6af0f69ba..c4e4cf8e20 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -2133,63 +2133,66 @@ (defn- block-content-on-mouse-down [e block block-id content edit-input-id] - (when-not (> (count content) (state/block-content-max-length (state/get-current-repo))) - (let [target (gobj/get e "target") - button (gobj/get e "buttons") - shift? (gobj/get e "shiftKey") - meta? (util/meta-key? e) - forbidden-edit? (target-forbidden-edit? target)] - (when-not forbidden-edit? (.stopPropagation e)) - (if (and meta? - (not (state/get-edit-input-id)) - (not (dom/has-class? target "page-ref")) - (not= "A" (gobj/get target "tagName"))) - (do - (util/stop e) - (state/conj-selection-block! (gdom/getElement block-id) :down) - (when block-id - (state/set-selection-start-block! block-id))) - (when (contains? #{1 0} button) - (when-not forbidden-edit? - (cond - (and shift? (state/get-selection-start-block-or-first)) - (do - (util/stop e) - (util/clear-selection!) - (editor-handler/highlight-selection-area! block-id)) + (let [repo (state/get-current-repo)] + (when-not (> (count content) (state/block-content-max-length repo)) + (let [target (gobj/get e "target") + button (gobj/get e "buttons") + shift? (gobj/get e "shiftKey") + meta? (util/meta-key? e) + forbidden-edit? (target-forbidden-edit? target)] + (when-not forbidden-edit? (.stopPropagation e)) + (if (and meta? + (not (state/get-edit-input-id)) + (not (dom/has-class? target "page-ref")) + (not= "A" (gobj/get target "tagName"))) + (do + (util/stop e) + (state/conj-selection-block! (gdom/getElement block-id) :down) + (when block-id + (state/set-selection-start-block! block-id))) + (when (contains? #{1 0} button) + (when-not forbidden-edit? + (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!) + 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 (some-> (gdom/getElement block-id) - (dom/by-class "block-content-wrapper") - first - util/caret-range) - {:block/keys [content format]} block - content (->> content - (property-edit/remove-built-in-properties-when-file-based - (state/get-current-repo) 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 (some-> (gdom/getElement block-id) + (dom/by-class "block-content-wrapper") + first + util/caret-range) + {:block/keys [content format]} block + content (if (config/db-based-graph? repo) + content + (->> content + (property-edit/remove-built-in-properties-when-file-based + (state/get-current-repo) 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?] diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index f871af0905..8f5b73640b 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -1766,7 +1766,9 @@ content (.-value input) last-input-char (util/nth-safe content (dec pos)) last-prev-input-char (util/nth-safe content (dec (dec pos))) - prev-prev-input-char (util/nth-safe content (- pos 3))] + prev-prev-input-char (util/nth-safe content (- pos 3)) + repo (state/get-current-repo) + db-based? (config/db-based-graph? repo)] ;; TODO: is it cross-browser compatible? ;; (not= (gobj/get native-e "inputType") "insertFromPaste") @@ -1792,7 +1794,8 @@ (and (= last-input-char last-prev-input-char commands/colon) (or (nil? prev-prev-input-char) - (= prev-prev-input-char "\n"))) + (= prev-prev-input-char "\n")) + (not db-based?)) (do (cursor/move-cursor-backward input 2) (state/set-editor-action-data! {:pos (cursor/get-caret-pos input)}) @@ -1801,12 +1804,15 @@ (and (not= :property-search (state/get-editor-action)) (let [{:keys [line start-pos]} (text-util/get-current-line-by-pos (.-value input) (dec pos))] - (text-util/wrapped-by? line (- pos start-pos) "" gp-property/colons))) + (text-util/wrapped-by? line (- pos start-pos) "" gp-property/colons)) + (not db-based?)) (do (state/set-editor-action-data! {:pos (cursor/get-caret-pos input)}) (state/set-editor-action! :property-search)) - (and (= last-input-char commands/colon) (= :property-search (state/get-editor-action))) + (and (= last-input-char commands/colon) + (= :property-search (state/get-editor-action)) + (not db-based?)) (state/clear-editor-action!) ;; Open "Search page or New page" auto-complete diff --git a/src/main/frontend/modules/outliner/core.cljs b/src/main/frontend/modules/outliner/core.cljs index 8a4d43974b..e13423cc00 100644 --- a/src/main/frontend/modules/outliner/core.cljs +++ b/src/main/frontend/modules/outliner/core.cljs @@ -247,12 +247,15 @@ (-save [this txs-state] (assert (ds/outliner-txs-state? txs-state) "db should be satisfied outliner-tx-state?") - (let [m (-> (:data this) + (let [m* (-> (:data this) (dissoc :block/children :block/meta :block.temp/top? :block.temp/bottom? :block/title :block/body :block/level) gp-util/remove-nils block-with-timestamps fix-tag-ids) + m (if (config/db-based-graph? (state/get-current-repo)) + (dissoc m* :block/properties :block/properties-order :block/properties-text-values) + m*) id (:db/id (:data this)) block-entity (db/entity id)] (when id