feat: add new command :editor/replace-block-reference-at-point

binding to 'ctrl+c ctrl+c'
This commit is contained in:
rcmerci
2021-06-20 23:05:56 +08:00
committed by Tienson Qin
parent 059943db17
commit 6d4bb1422b
2 changed files with 22 additions and 2 deletions

View File

@@ -3012,3 +3012,18 @@
(->> (:block/uuid (state/get-edit-block))
select-block!)
(state/clear-edit!)))))
(defn replace-block-reference-with-content-at-point
[]
(when-let [{:keys [content start end]} (thingatpt/block-ref-at-point)]
(let [block-ref-id (subs content 2 (- (count content) 2))]
(when-let [block (db/pull [:block/uuid (uuid block-ref-id)])]
(let [block-content (:block/content block)
format (or (:block/format block) :markdown)
block-content-without-prop (property/remove-properties format block-content)]
(when-let [input (state/get-input)]
(when-let [current-block-content (gobj/get input "value")]
(let [block-content* (str (subs current-block-content 0 start)
block-content-without-prop
(subs current-block-content end))]
(state/set-block-content-and-last-pos! input block-content* 1)))))))))