Merge remote-tracking branch 'upstream/master' into whiteboards

This commit is contained in:
Peng Xiao
2022-08-15 22:31:08 +08:00
22 changed files with 696 additions and 335 deletions

View File

@@ -205,8 +205,8 @@
(defn clear-selection!
[]
(util/select-unhighlight! (dom/by-class "selected"))
(state/clear-selection!))
(state/clear-selection!)
(util/select-unhighlight! (dom/by-class "selected")))
(defn- text-range-by-lst-fst-line [content [direction pos]]
(case direction
@@ -1073,8 +1073,11 @@
(when-let [blocks (seq (get-selected-blocks))]
;; remove embeds, references and queries
(let [dom-blocks (remove (fn [block]
(or (= "true" (dom/attr block "data-transclude"))
(= "true" (dom/attr block "data-query")))) blocks)]
(or (= "true" (dom/attr block "data-transclude"))
(= "true" (dom/attr block "data-query")))) blocks)
dom-blocks (if (seq dom-blocks) dom-blocks
(remove (fn [block]
(= "true" (dom/attr block "data-transclude"))) blocks))]
(when (seq dom-blocks)
(let [repo (state/get-current-repo)
block-uuids (distinct (map #(uuid (dom/attr % "blockid")) dom-blocks))
@@ -1220,8 +1223,7 @@
(defn clear-last-selected-block!
[]
(let [block (state/drop-last-selection-block!)]
(util/select-unhighlight! [block])))
(state/drop-last-selection-block!))
(defn highlight-selection-area!
[end-block]
@@ -1236,18 +1238,18 @@
(defn- select-block-up-down
[direction]
(cond
;; when editing, quit editing and select current block
;; when editing, quit editing and select current block
(state/editing?)
(state/exit-editing-and-set-selected-blocks! [(gdom/getElement (state/get-editing-block-dom-id))])
;; when selection and one block selected, select next block
;; when selection and one block selected, select next block
(and (state/selection?) (== 1 (count (state/get-selection-blocks))))
(let [f (if (= :up direction) util/get-prev-block-non-collapsed util/get-next-block-non-collapsed-skip)
element (f (first (state/get-selection-blocks)))]
(when element
(state/conj-selection-block! element direction)))
;; if same direction, keep conj on same direction
;; if same direction, keep conj on same direction
(and (state/selection?) (= direction (state/get-selection-direction)))
(let [f (if (= :up direction) util/get-prev-block-non-collapsed util/get-next-block-non-collapsed-skip)
first-last (if (= :up direction) first last)
@@ -1255,7 +1257,7 @@
(when element
(state/conj-selection-block! element direction)))
;; if different direction, keep clear until one left
;; if different direction, keep clear until one left
(state/selection?)
(clear-last-selected-block!))
nil)
@@ -1734,6 +1736,13 @@
:markdown (util/format "![%s](%s)" label link)
:org (util/format "[[%s]]"))))
(defn handle-command-input-close [id]
(state/set-editor-show-input! nil)
(when-let [saved-cursor (state/get-editor-last-pos)]
(when-let [input (gdom/getElement id)]
(.focus input)
(cursor/move-cursor-to input saved-cursor))))
(defn handle-command-input [command id format m]
;; TODO: Add error handling for when user doesn't provide a required field.
;; (The current behavior is to just revert back to the editor.)
@@ -1757,41 +1766,24 @@
nil)
(state/set-editor-show-input! nil)
(when-let [saved-cursor (state/get-editor-last-pos)]
(when-let [input (gdom/getElement id)]
(.focus input)
(cursor/move-cursor-to input saved-cursor))))
(defn get-search-q
[]
(when-let [id (state/get-edit-input-id)]
(when-let [input (gdom/getElement id)]
(let [current-pos (cursor/pos input)
pos (state/get-editor-last-pos)
edit-content (or (state/sub [:editor/content id]) "")]
(or
@*selected-text
(gp-util/safe-subs edit-content pos current-pos))))))
(handle-command-input-close id))
(defn close-autocomplete-if-outside
[input]
(when (and input
(state/get-editor-action)
(not (wrapped-by? input page-ref/left-brackets page-ref/right-brackets)))
(when (get-search-q)
(let [value (gobj/get input "value")
pos (state/get-editor-last-pos)
current-pos (cursor/pos input)
between (gp-util/safe-subs value (min pos current-pos) (max pos current-pos))]
(when (and between
(or
(string/includes? between "[")
(string/includes? between "]")
(string/includes? between "(")
(string/includes? between ")")))
(state/clear-editor-action!))))))
(let [value (gobj/get input "value")
pos (state/get-editor-last-pos)
current-pos (cursor/pos input)
between (gp-util/safe-subs value (min pos current-pos) (max pos current-pos))]
(when (and between
(or
(string/includes? between "[")
(string/includes? between "]")
(string/includes? between "(")
(string/includes? between ")")))
(state/clear-editor-action!)))))
(defn resize-image!
[block-id metadata full_text size]
@@ -1821,7 +1813,7 @@
(reset! *auto-save-timeout
(js/setTimeout
(fn []
(when (state/input-idle? repo)
(when (state/input-idle? repo :diff 500)
(state/set-editor-op! :auto-save)
; don't auto-save for page's properties block
(save-current-block! {:skip-properties? true})
@@ -2816,7 +2808,7 @@
nil))))
(defn ^:large-vars/cleanup-todo keyup-handler
[_state input input-id search-timeout]
[_state input input-id]
(fn [e key-code]
(when-not (util/event-is-composing? e)
(let [current-pos (cursor/pos input)
@@ -2889,7 +2881,7 @@
(when (and (not editor-action) (not non-enter-processed?))
(cond
;; When you type text inside square brackets
(and (not (contains? #{"ArrowDown" "ArrowLeft" "ArrowRight" "ArrowUp"} k))
(and (not (contains? #{"ArrowDown" "ArrowLeft" "ArrowRight" "ArrowUp" "Escape"} k))
(wrapped-by? input page-ref/left-brackets page-ref/right-brackets))
(let [orig-pos (cursor/get-caret-pos input)
value (gobj/get input "value")
@@ -2937,11 +2929,11 @@
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
(state/set-editor-show-block-commands!))
(nil? @search-timeout)
(close-autocomplete-if-outside input)
:else
nil)))
(close-autocomplete-if-outside input)
(when-not (or (= k "Shift") is-processed?)
(state/set-last-key-code! {:key-code key-code
:code code