Browse Source

Raw paste should only do basic pasting

Fix #6815 and fix #6142.
Raw paste used to do this before #5396 was introduced.
We accidentally coupled rich and raw paste starting at
999defdad1b567b368a182eb5da1a44798eb8d84 which then caused these issues
Gabriel Horner 2 years ago
parent
commit
72298d23c8
2 changed files with 23 additions and 14 deletions
  1. 1 1
      src/main/frontend/handler/paste.cljs
  2. 22 13
      src/test/frontend/handler/paste_test.cljs

+ 1 - 1
src/main/frontend/handler/paste.cljs

@@ -192,7 +192,7 @@
          (utils/getClipText
           (fn [clipboard-data]
             (when (state/get-input)
-              (paste-text-or-blocks-aux input e clipboard-data nil)))
+              (editor-handler/insert clipboard-data true)))
           (fn [error]
             (js/console.error error)))
          (let [clipboard-data (gobj/get e "clipboardData")

+ 22 - 13
src/test/frontend/handler/paste_test.cljs

@@ -85,26 +85,34 @@
         reset
         [utils/getClipText (fn [cb] (cb clipboard))
          state/get-input (constantly #js {:value "block"})
-         commands/delete-selection! (constantly nil)
-         commands/simple-insert! (fn [_input text] (p/resolved text))
-         util/get-selected-text (constantly nil)]
+         editor-handler/insert (fn [text _] (p/resolved text))]
         (p/let [result ((paste-handler/editor-on-paste! nil true))]
                (is (= expected-paste result))
                (reset))))))
 
-(deftest-async editor-on-paste-normal-with-link
-  (testing "Normal paste for link should paste macro wrapped link"
+(deftest-async ^:focus editor-on-paste-raw-with-multi-line
+  (let [clipboard "a\n\na"
+        expected-paste "a\n\na"]
+    (test-helper/with-reset
+      reset
+      [utils/getClipText (fn [cb] (cb clipboard))
+       state/get-input (constantly #js {:value "block"})
+       editor-handler/insert (fn [text _] (p/resolved text))]
+      (p/let [result ((paste-handler/editor-on-paste! nil true))]
+             (is (= expected-paste result))
+             (reset)))))
+
+(deftest-async editor-on-paste-with-link
+  (testing "Formatted paste for link should paste macro wrapped link"
     (let [clipboard "https://www.youtube.com/watch?v=xu9p5ynlhZk"
           expected-paste "{{video https://www.youtube.com/watch?v=xu9p5ynlhZk}}"]
       (test-helper/with-reset
         reset
-        ;; These redefs are like above
         [utils/getClipText (fn [cb] (cb clipboard))
          state/get-input (constantly #js {:value "block"})
+         ;; paste-copied-blocks-or-text mocks below
          commands/delete-selection! (constantly nil)
          commands/simple-insert! (fn [_input text] (p/resolved text))
-         util/get-selected-text (constantly nil)
-         ;; Specific redefs to normal paste
          util/stop (constantly nil)
          html-parser/convert (constantly nil)]
         (p/let [result ((paste-handler/editor-on-paste! nil)
@@ -112,19 +120,20 @@
                (is (= expected-paste result))
                (reset))))))
 
-(deftest-async editor-on-paste-raw-with-selection
+(deftest-async editor-on-paste-with-selection-in-property
   (let [clipboard "after"
         expected-paste "after"
-        selected-text "before"
         block-content "test:: before"]
     (test-helper/with-reset
       reset
       [utils/getClipText (fn [cb] (cb clipboard))
        state/get-input (constantly #js {:value block-content})
-       editor-handler/get-selection-and-format (constantly {:value block-content})
+       ;; paste-copied-blocks-or-text mocks below
        commands/delete-selection! (constantly nil)
        commands/simple-insert! (fn [_input text] (p/resolved text))
-       util/get-selected-text (constantly selected-text)]
-      (p/let [result ((paste-handler/editor-on-paste! nil true))]
+       util/stop (constantly nil)
+       html-parser/convert (constantly nil)]
+      (p/let [result ((paste-handler/editor-on-paste! nil)
+                      #js {:clipboardData #js {:getData (constantly clipboard)}})]
              (is (= expected-paste result))
              (reset)))))