Merge branch 'master' into enhance/graph-parser-part-four

This commit is contained in:
Gabriel Horner
2022-05-30 10:18:34 -04:00
50 changed files with 987 additions and 388 deletions

View File

@@ -56,7 +56,8 @@
[promesa.core :as p]
[logseq.graph-parser.util :as gp-util]
[logseq.graph-parser.mldoc :as gp-mldoc]
[logseq.graph-parser.block :as gp-block]))
[logseq.graph-parser.block :as gp-block]
[frontend.extensions.html-parser :as html-parser]))
;; FIXME: should support multiple images concurrently uploading
@@ -963,9 +964,7 @@
(defn select-block!
[block-uuid]
(let [blocks (js/document.getElementsByClassName (str block-uuid))]
(when (seq blocks)
(state/exit-editing-and-set-selected-blocks! blocks))))
(block-handler/select-block! block-uuid))
(defn- compose-copied-blocks-contents
[repo block-ids]
@@ -978,7 +977,7 @@
(into [] (state/get-export-block-text-remove-options)))))
(defn copy-selection-blocks
[]
[html?]
(when-let [blocks (seq (state/get-selection-blocks))]
(let [repo (state/get-current-repo)
ids (distinct (keep #(when-let [id (dom/attr % "blockid")]
@@ -986,7 +985,8 @@
content (compose-copied-blocks-contents repo ids)
block (db/entity [:block/uuid (first ids)])]
(when block
(common-handler/copy-to-clipboard-without-id-property! (:block/format block) content)
(let [html (export/export-blocks-as-html repo ids)]
(common-handler/copy-to-clipboard-without-id-property! (:block/format block) content (when html? html)))
(state/set-copied-blocks content ids)
(notification/show! "Copied!" :success)))))
@@ -1055,7 +1055,7 @@
(defn cut-selection-blocks
[copy?]
(when copy? (copy-selection-blocks))
(when copy? (copy-selection-blocks true))
(when-let [blocks (seq (get-selected-blocks))]
;; remove embeds, references and queries
(let [dom-blocks (remove (fn [block]
@@ -1194,9 +1194,10 @@
(when-let [block (db/pull [:block/uuid block-id])]
(let [repo (state/get-current-repo)
;; TODO: support org mode
md-content (compose-copied-blocks-contents repo [block-id])]
md-content (compose-copied-blocks-contents repo [block-id])
html (export/export-blocks-as-html repo [block-id])]
(state/set-copied-full-blocks md-content [block])
(common-handler/copy-to-clipboard-without-id-property! (:block/format block) md-content)
(common-handler/copy-to-clipboard-without-id-property! (:block/format block) md-content html)
(delete-block-aux! block true))))
(defn clear-last-selected-block!
@@ -2634,49 +2635,49 @@
nil
;; FIXME: On mobile, a backspace click to call keydown-backspace-handler
;; does not work sometimes in an empty block, hence the empty block
;; does not work if cursor is at the beginning of a block, hence the block
;; can't be deleted. Need to figure out why and find a better solution.
(and (mobile-util/native-platform?)
(= key "Backspace")
(= value ""))
(zero? pos))
(do
(util/stop e)
(delete-block! (state/get-current-repo) false))
(let [block (state/get-edit-block)
top-block? (= (:block/left block) (:block/page block))
root-block? (= (:block/container block) (str (:block/uuid block)))
repo (state/get-current-repo)]
(when (and (if top-block? (string/blank? value) true)
(not root-block?))
(delete-block! repo false))))
(and (= key "#")
(and
(> pos 0)
(= "#" (util/nth-safe value (dec pos)))))
(and (> pos 0)
(= "#" (util/nth-safe value (dec pos)))))
(state/set-editor-show-page-search-hashtag! false)
(and
(contains? (set/difference (set (keys reversed-autopair-map))
#{"`"})
key)
(and (contains? (set/difference (set (keys reversed-autopair-map))
#{"`"})
key)
(= (get-current-input-char input) key))
(do
(util/stop e)
(cursor/move-cursor-forward input))
(do (util/stop e)
(cursor/move-cursor-forward input))
(and (autopair-when-selected key) (string/blank? (util/get-selected-text)))
nil
(and (not (string/blank? (util/get-selected-text)))
(contains? keycode/left-square-brackets-keys key))
(do
(autopair input-id "[" format nil)
(util/stop e))
(do (autopair input-id "[" format nil)
(util/stop e))
(and (not (string/blank? (util/get-selected-text)))
(contains? keycode/left-paren-keys key))
(do
(util/stop e)
(autopair input-id "(" format nil))
(do (util/stop e)
(autopair input-id "(" format nil))
(contains? (set (keys autopair-map)) key)
(do
(util/stop e)
(autopair input-id key format nil))
(do (util/stop e)
(autopair input-id key format nil))
hashtag?
(do
@@ -2888,8 +2889,8 @@
(let [copied-blocks (state/get-copied-blocks)
copied-block-ids (:copy/block-ids copied-blocks)
copied-graph (:copy/graph copied-blocks)
input (state/get-input)
*stop-event? (atom true)]
input (state/get-input)]
(util/stop e)
(cond
;; Internal blocks by either copy or cut blocks
(and
@@ -2917,7 +2918,8 @@
:else
;; from external
(let [format (or (db/get-page-format (state/get-current-page)) :markdown)]
(let [format (or (db/get-page-format (state/get-current-page)) :markdown)
text (string/trim text)]
(match [format
(nil? (util/safe-re-find #"(?m)^\s*(?:[-+*]|#+)\s+" text))
(nil? (util/safe-re-find #"(?m)^\s*\*+\s+" text))
@@ -2929,18 +2931,16 @@
(paste-text-parseable format text)
[:markdown true _ false]
(paste-segmented-text format (string/trim text))
(paste-segmented-text format text)
[:markdown true _ true]
(reset! *stop-event? false)
(commands/simple-insert! (state/get-edit-input-id) text nil)
[:org _ true false]
(paste-segmented-text format (string/trim text))
(paste-segmented-text format text)
[:org _ true true]
(reset! *stop-event? false))))
(when @*stop-event?
(util/stop e))))
(commands/simple-insert! (state/get-edit-input-id) text nil))))))
(defn paste-text-in-one-block-at-point
[]
@@ -2958,7 +2958,14 @@
[id]
(fn [e]
(state/set-state! :editor/on-paste? true)
(let [text (.getData (gobj/get e "clipboardData") "text")
(let [clipboard-data (gobj/get e "clipboardData")
html (.getData clipboard-data "text/html")
edit-block (state/get-edit-block)
format (or (:block/format edit-block) :markdown)
initial-text (.getData clipboard-data "text")
text (if-not (string/blank? html)
(html-parser/convert format html)
initial-text)
input (state/get-input)]
(if-not (string/blank? text)
(if (or (thingatpt/markdown-src-at-point input)
@@ -2982,7 +2989,7 @@
(defn shortcut-copy-selection
[_e]
(copy-selection-blocks))
(copy-selection-blocks true))
(defn shortcut-cut-selection
[e]
@@ -3030,6 +3037,19 @@
:else
(js/document.execCommand "copy"))))
(defn shortcut-copy-text
"shortcut copy action:
* when in selection mode, copy selected blocks
* when in edit mode with text selected, copy selected text as normal"
[_e]
(when-not (auto-complete?)
(cond
(state/selection?)
(copy-selection-blocks false)
:else
(js/document.execCommand "copy"))))
(defn shortcut-cut
"shortcut cut action:
* when in selection mode, cut selected blocks