fix: mod+e to embed block

Also being able to paste copied block ref when /node embed.
This commit is contained in:
Tienson Qin
2025-02-21 00:42:26 +08:00
parent abb52d61a7
commit 8f6a7d85b5
4 changed files with 35 additions and 9 deletions

View File

@@ -30,6 +30,7 @@
[goog.dom :as gdom]
[goog.string :as gstring]
[logseq.common.util :as common-util]
[logseq.common.util.page-ref :as page-ref]
[logseq.db :as ldb]
[logseq.db.frontend.class :as db-class]
[logseq.graph-parser.property :as gp-property]
@@ -338,7 +339,17 @@
(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))))
(let [db? (config/db-based-graph? (state/get-current-repo))
embed? (and db? (= @commands/*current-command "Block embed"))
page (when embed? (page-ref/get-page-name edit-content))
embed-block-id (when (and embed? page (common-util/uuid-string? page))
(uuid page))]
(if embed-block-id
(let [f (block-on-chosen-handler true input id q format nil)
block (db/entity embed-block-id)]
(when block (f block))
nil)
(block-search-auto-complete edit-block input id q format selected-text))))))
(rum/defc template-search-aux
[id q]

View File

@@ -3235,10 +3235,14 @@
(when-let [block-id (:block/uuid current-block)]
(let [db? (config/db-based-graph? (state/get-current-repo))]
(if (= format "embed")
(copy-block-ref! block-id
(if db?
block-ref/->block-ref
#(str "{{embed ((" % "))}}")))
(if db?
(p/do!
(save-current-block!)
(util/copy-to-clipboard! (page-ref/->page-ref block-id)
{:graph (state/get-current-repo)
:blocks [{:block/uuid (:block/uuid current-block)}]
:embed-block? true}))
(copy-block-ref! block-id #(str "{{embed ((" % "))}}")))
(copy-block-ref! block-id
(if db?
page-ref/->page-ref

View File

@@ -190,7 +190,7 @@
[input text e html]
(util/stop e)
(->
(p/let [{:keys [graph blocks]} (get-copied-blocks)]
(p/let [{:keys [graph blocks embed-block?]} (get-copied-blocks)]
(if (and (seq blocks) (= graph (state/get-current-repo)))
;; Handle internal paste
(let [revert-cut-txs (get-revert-cut-txs blocks)
@@ -198,8 +198,18 @@
blocks (if (config/db-based-graph? (state/get-current-repo))
(map (fn [b] (dissoc b :block/properties)) blocks)
blocks)]
(editor-handler/paste-blocks blocks {:revert-cut-txs revert-cut-txs
:keep-uuid? keep-uuid?}))
(if embed-block?
(when-let [block-id (:block/uuid (first blocks))]
(when-let [current-block (state/get-edit-block)]
(p/do!
(editor-handler/api-insert-new-block! ""
{:block-uuid (:block/uuid current-block)
:sibling? true
:replace-empty-target? true
:other-attrs {:block/link (:db/id (db/entity [:block/uuid block-id]))}})
(state/clear-edit!))))
(editor-handler/paste-blocks blocks {:revert-cut-txs revert-cut-txs
:keep-uuid? keep-uuid?})))
(paste-copied-text input text html)))
(p/catch (fn [error]
(log/error :msg "Paste failed" :exception error)

View File

@@ -807,7 +807,7 @@
#?(:cljs
(defn copy-to-clipboard!
[text & {:keys [graph html blocks owner-window]}]
[text & {:keys [graph html blocks embed-block? owner-window]}]
(let [blocks (map (fn [block] (if (de/entity? block)
(-> (into {} block)
;; FIXME: why :db/id is not included?
@@ -820,6 +820,7 @@
:blocks (when (and graph (seq blocks))
(pr-str
{:graph graph
:embed-block? embed-block?
:blocks (mapv #(dissoc % :block.temp/fully-loaded? %) blocks)}))}))]
(if owner-window
(utils/writeClipboard data owner-window)