mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 22:25:01 +00:00
enhance(ux): convert a url to markdown/org link when pasting
This commit is contained in:
@@ -62,7 +62,7 @@
|
||||
(defonce *asset-uploading-process (atom 0))
|
||||
(defonce *selected-text (atom nil))
|
||||
|
||||
(defn- get-selection-and-format
|
||||
(defn get-selection-and-format
|
||||
[]
|
||||
(when-let [block (state/get-edit-block)]
|
||||
(when (:block/uuid block)
|
||||
|
||||
@@ -89,47 +89,49 @@
|
||||
(when (seq blocks)
|
||||
(state/set-copied-full-blocks! blocks)
|
||||
(editor-handler/paste-blocks blocks {}))))
|
||||
(cond
|
||||
(and (gp-util/url? text)
|
||||
(not (string/blank? (util/get-selected-text))))
|
||||
(do
|
||||
(util/stop e)
|
||||
(editor-handler/html-link-format! text))
|
||||
(let [{:keys [value]} (editor-handler/get-selection-and-format)]
|
||||
(cond
|
||||
(and (or (gp-util/url? text)
|
||||
(and value (gp-util/url? (string/trim value))))
|
||||
(not (string/blank? (util/get-selected-text))))
|
||||
(do
|
||||
(util/stop e)
|
||||
(editor-handler/html-link-format! text))
|
||||
|
||||
(and (text/block-ref? text)
|
||||
(editor-handler/wrapped-by? input "((" "))"))
|
||||
(do
|
||||
(util/stop e)
|
||||
(commands/simple-insert! (state/get-edit-input-id) (text/get-block-ref text) nil))
|
||||
(and (text/block-ref? text)
|
||||
(editor-handler/wrapped-by? input "((" "))"))
|
||||
(do
|
||||
(util/stop e)
|
||||
(commands/simple-insert! (state/get-edit-input-id) (text/get-block-ref text) nil))
|
||||
|
||||
:else
|
||||
;; from external
|
||||
(let [format (or (db/get-page-format (state/get-current-page)) :markdown)
|
||||
text (or (when-not (string/blank? html)
|
||||
(html-parser/convert format html))
|
||||
text)]
|
||||
(util/stop e)
|
||||
(match [format
|
||||
(nil? (util/safe-re-find #"(?m)^\s*(?:[-+*]|#+)\s+" text))
|
||||
(nil? (util/safe-re-find #"(?m)^\s*\*+\s+" text))
|
||||
(nil? (util/safe-re-find #"(?:\r?\n){2,}" text))]
|
||||
[:markdown false _ _]
|
||||
(paste-text-parseable format text)
|
||||
:else
|
||||
;; from external
|
||||
(let [format (or (db/get-page-format (state/get-current-page)) :markdown)
|
||||
text (or (when-not (string/blank? html)
|
||||
(html-parser/convert format html))
|
||||
text)]
|
||||
(util/stop e)
|
||||
(match [format
|
||||
(nil? (util/safe-re-find #"(?m)^\s*(?:[-+*]|#+)\s+" text))
|
||||
(nil? (util/safe-re-find #"(?m)^\s*\*+\s+" text))
|
||||
(nil? (util/safe-re-find #"(?:\r?\n){2,}" text))]
|
||||
[:markdown false _ _]
|
||||
(paste-text-parseable format text)
|
||||
|
||||
[:org _ false _]
|
||||
(paste-text-parseable format text)
|
||||
[:org _ false _]
|
||||
(paste-text-parseable format text)
|
||||
|
||||
[:markdown true _ false]
|
||||
(paste-segmented-text format text)
|
||||
[:markdown true _ false]
|
||||
(paste-segmented-text format text)
|
||||
|
||||
[:markdown true _ true]
|
||||
(commands/simple-insert! (state/get-edit-input-id) text nil)
|
||||
[:markdown true _ true]
|
||||
(commands/simple-insert! (state/get-edit-input-id) text nil)
|
||||
|
||||
[:org _ true false]
|
||||
(paste-segmented-text format text)
|
||||
[:org _ true false]
|
||||
(paste-segmented-text format text)
|
||||
|
||||
[:org _ true true]
|
||||
(commands/simple-insert! (state/get-edit-input-id) text nil)))))))
|
||||
[:org _ true true]
|
||||
(commands/simple-insert! (state/get-edit-input-id) text nil))))))))
|
||||
|
||||
(defn paste-text-in-one-block-at-point
|
||||
[]
|
||||
|
||||
Reference in New Issue
Block a user