From ce11e09c7bbbee6e5b451e4628ac480f07b355e0 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Fri, 9 Aug 2024 13:02:02 +0800 Subject: [PATCH] enhance: disable (()) to trigger node embed to avoid confusion --- src/main/frontend/commands.cljs | 6 +++--- src/main/frontend/components/editor.cljs | 2 +- src/main/frontend/handler/editor.cljs | 14 +++++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/frontend/commands.cljs b/src/main/frontend/commands.cljs index d03193f42c..142bd17c59 100644 --- a/src/main/frontend/commands.cljs +++ b/src/main/frontend/commands.cljs @@ -135,8 +135,7 @@ (defn db-based-embed-block [] - [[:editor/input "(())" {:last-pattern command-trigger - :backward-pos 2}] + [[:editor/input "" {:last-pattern command-trigger}] [:editor/search-block :embed]]) (defn get-statuses @@ -792,7 +791,8 @@ (defmethod handle-step :editor/search-block [[_ type]] (when (and (= type :embed) (config/db-based-graph? (state/get-current-repo))) - (reset! *current-command "Block embed")) + (reset! *current-command "Block embed") + (state/set-editor-action-data! {:pos (cursor/get-caret-pos (state/get-input))})) (state/set-editor-action! :block-search)) (defmethod handle-step :editor/search-template [[_]] diff --git a/src/main/frontend/components/editor.cljs b/src/main/frontend/components/editor.cljs index 90e08f47c9..6e53002af2 100644 --- a/src/main/frontend/components/editor.cljs +++ b/src/main/frontend/components/editor.cljs @@ -297,7 +297,7 @@ selected-text (editor-handler/get-selected-text) q (or selected-text - (when (> (count edit-content) current-pos) + (when (>= (count edit-content) current-pos) (subs edit-content pos current-pos)))] (when input (block-search-auto-complete edit-block input id q format selected-text)))) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index e7b0eb7a19..a71b220b17 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -1623,9 +1623,15 @@ (state/set-editor-action-data! {:pos (cursor/get-caret-pos input) :selected selected})) + (and (= prefix block-ref/left-parens) + (config/db-based-graph? (state/get-current-repo))) + (notification/show! + "To reference a node, please use `[[]]`." + :warning) + (= prefix block-ref/left-parens) - (let [db-based? (config/db-based-graph? (state/get-current-repo))] - (commands/handle-step [:editor/search-block (if db-based? :embed :reference)]) + (do + (commands/handle-step [:editor/search-block :reference]) (state/set-editor-action-data! {:pos (cursor/get-caret-pos input) :selected selected}))))))) @@ -1857,7 +1863,9 @@ (not (wrapped-by? input block-ref/left-parens block-ref/right-parens)) ;; wrapped-by? doesn't detect multiple beginnings when ending with "" so ;; use subs to correctly detect current hashtag - (not (text-util/wrapped-by? (subs (.-value input) 0 (cursor/pos input)) (cursor/pos input) commands/hashtag ""))) + (not (text-util/wrapped-by? (subs (.-value input) 0 (cursor/pos input)) (cursor/pos input) commands/hashtag "")) + (not (and (config/db-based-graph? (state/get-current-repo)) + (= :block-search (state/get-editor-action))))) (state/clear-editor-action!))) (defn resize-image!