Parcourir la source

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

binding to 'ctrl+c ctrl+c'
rcmerci il y a 4 ans
Parent
commit
6d4bb1422b

+ 15 - 0
src/main/frontend/handler/editor.cljs

@@ -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)))))))))

+ 7 - 2
src/main/frontend/modules/shortcut/config.cljs

@@ -146,7 +146,11 @@
     :editor/backward-kill-word
     {:desc    "Kill a word backwards"
      :binding (if mac? false "alt+w")
-     :fn      editor-handler/backward-kill-word}}
+     :fn      editor-handler/backward-kill-word}
+    :editor/replace-block-reference-at-point
+    {:desc "Replace block reference with its content at point"
+     :binding "ctrl+c ctrl+c"
+     :fn editor-handler/replace-block-reference-with-content-at-point}}
 
    :shortcut.handler/editor-global
    ^{:before m/enable-when-not-component-editing!}
@@ -376,7 +380,8 @@
     :editor/forward-word
     :editor/backward-word
     :editor/forward-kill-word
-    :editor/backward-kill-word]
+    :editor/backward-kill-word
+    :editor/replace-block-reference-at-point]
 
    :shortcut.category/block-selection
    ^{:doc "Block selection (press Esc to quit selection)"}