diff --git a/src/main/frontend/handler/paste.cljs b/src/main/frontend/handler/paste.cljs index e996f55333..776dfb73ba 100644 --- a/src/main/frontend/handler/paste.cljs +++ b/src/main/frontend/handler/paste.cljs @@ -197,9 +197,8 @@ (if raw-paste? (utils/getClipText (fn [clipboard-data] - (when-let [_ (state/get-input)] - (let [text clipboard-data] - (paste-text-or-blocks-aux input e text nil)))) + (when (state/get-input) + (paste-text-or-blocks-aux input e clipboard-data nil))) (fn [error] (js/console.error error))) (let [clipboard-data (gobj/get e "clipboardData") diff --git a/src/test/frontend/handler/paste_test.cljs b/src/test/frontend/handler/paste_test.cljs index d56cc3b1ec..dba60516e6 100644 --- a/src/test/frontend/handler/paste_test.cljs +++ b/src/test/frontend/handler/paste_test.cljs @@ -1,6 +1,12 @@ (ns frontend.handler.paste-test - (:require [cljs.test :refer [deftest are]] + (:require [cljs.test :refer [deftest are is testing]] + [frontend.test.helper :as test-helper :include-macros true :refer [deftest-async]] [goog.object :as gobj] + ["/frontend/utils" :as utils] + [frontend.state :as state] + [frontend.commands :as commands] + [frontend.util :as util] + [promesa.core :as p] [frontend.handler.paste :as paste-handler])) (deftest try-parse-as-json-result-parse-test @@ -30,7 +36,7 @@ "[{\"number\": 1234}]" nil nil ;; invalid JSON "{number: 1234}" nil nil)) - + (deftest selection-within-link-test (are [x y] (= (#'paste-handler/selection-within-link? x) y) {:format :markdown @@ -67,4 +73,18 @@ :value "[logseq](https://logseq.com) is developed with [Clojure](https://clojure.org)" :selection-start 9 :selection-end 76 - :selection "https://logseq.com) is developed with [Clojure](https://clojure.org"} false)) + :selection "https://logseq.com) is developed with [Clojure](https://clojure.org"} false)) + +(deftest-async editor-on-paste-raw-link + (testing "Raw paste for link should just paste link" + (let [clipboard "https://www.youtube.com/watch?v=xu9p5ynlhZk" + expected-paste "https://www.youtube.com/watch?v=xu9p5ynlhZk"] + (test-helper/with-reset + 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)] + (p/let [result ((paste-handler/editor-on-paste! nil true))] + (is (= expected-paste result)))))))