Browse Source

enhance(dwim): dwim on paste in source block or admonition

Clipboard data with newlines will be inserted as raw text in source
block or admonition.
leizhe 4 years ago
parent
commit
51ce3c4cf7
1 changed files with 14 additions and 12 deletions
  1. 14 12
      src/main/frontend/handler/editor.cljs

+ 14 - 12
src/main/frontend/handler/editor.cljs

@@ -3122,13 +3122,25 @@
           [:org _ true true]
           nil)))))
 
+(defn paste-text-in-one-block-at-point
+  []
+  (utils/getClipText
+   (fn [clipboard-data]
+     (when-let [_ (state/get-input)]
+       (state/append-current-edit-content! clipboard-data)))
+   (fn [error]
+     (js/console.error error))))
+
 (defn editor-on-paste!
   [id]
   (fn [e]
     (state/set-state! :editor/on-paste? true)
-    (let [text (.getData (gobj/get e "clipboardData") "text")]
+    (let [text (.getData (gobj/get e "clipboardData") "text")
+          input (state/get-input)]
       (if-not (string/blank? text)
-        (paste-text text e)
+        (if (thingatpt/org-admonition&src-at-point input)
+          (paste-text-in-one-block-at-point)
+          (paste-text text e))
         (let [_handled
               (let [clipboard-data (gobj/get e "clipboardData")
                     files (.-files clipboard-data)]
@@ -3523,16 +3535,6 @@
                                         (subs current-block-content end))]
                 (state/set-block-content-and-last-pos! input block-content* 1)))))))))
 
-
-(defn paste-text-in-one-block-at-point
-  []
-  (utils/getClipText
-   (fn [clipboard-data]
-     (when-let [_ (state/get-input)]
-       (state/append-current-edit-content! clipboard-data)))
-   (fn [error]
-     (js/console.error error))))
-
 (defn copy-current-ref
   [block-id]
   (when block-id