Skip to content

Commit

Permalink
Fix Twitter's rename breaking macro wrapping (logseq#11325)
Browse files Browse the repository at this point in the history
* FIX twitter's rename causing automatic macro wrapping to not work

* ADD test to check for x => twitter macro expansion
  • Loading branch information
chiefnoah authored May 31, 2024
1 parent eb12697 commit b70768d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/frontend/handler/paste.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
(boolean (text-util/get-matched-video url))
(util/format "{{video %s}}" url)

(string/includes? url "twitter.com")
(or (string/includes? url "twitter.com") (string/includes? url "x.com"))
(util/format "{{twitter %s}}" url)))

(defn- try-parse-as-json
Expand Down
3 changes: 2 additions & 1 deletion src/main/frontend/quick_capture.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
(defn- is-tweet-link
[url]
(when (not-empty url)
(re-matches #"^https://twitter\.com/.*?/status/.*?$" url)))
(or (re-matches #"^https://twitter\.com/.*?/status/.*?$" url)
(re-matches #"^https://x\.com/.*?/status/.*?$" url))))

(defn quick-capture [args]
(let [{:keys [url title content page append]} (bean/->clj args)
Expand Down
18 changes: 17 additions & 1 deletion src/test/frontend/handler/paste_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@
(is (= expected-paste result))
(reset))))))

(deftest-async editor-on-paste-with-twitter-is-now-x-lol
(testing "Formatted paste for the site formerly known as twitter link should paste macro wrapped as twitter"
(let [clipboard "https://x.com/chiefnoah13/status/1792677792506843462"
expected-paste "{{twitter https://x.com/chiefnoah13/status/1792677792506843462}}"]
(test-helper/with-reset
reset
[commands/delete-selection! (constantly nil)
commands/simple-insert! (fn [_input text] (p/resolved text))
util/stop (constantly nil)
util/get-selected-text (constantly "")
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))))))

(deftest-async editor-on-paste-with-text-over-link
(testing "Paste text over a selected formatted link"
(let [actual-text (atom nil)
Expand Down Expand Up @@ -231,4 +247,4 @@
#js {:clipboardData #js {:getData (constantly clipboard)
:files files}})]
(is (= files (js->clj @pasted-file)))
(reset)))))
(reset)))))

0 comments on commit b70768d

Please sign in to comment.