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

pull/6345/head
Peng Xiao 2022-08-08 11:20:21 +08:00
commit 866b4793bd
1 changed files with 27 additions and 23 deletions

View File

@ -2451,7 +2451,10 @@
(state/exit-editing-and-set-selected-blocks! [block])))) (state/exit-editing-and-set-selected-blocks! [block]))))
(defn- select-up-down [direction] (defn- select-up-down [direction]
(let [selected (first (state/get-selection-blocks)) (let [selected-blocks (state/get-selection-blocks)
selected (case direction
:up (first selected-blocks)
:down (last selected-blocks))
f (case direction f (case direction
:up util/get-prev-block-non-collapsed :up util/get-prev-block-non-collapsed
:down util/get-next-block-non-collapsed) :down util/get-next-block-non-collapsed)
@ -3079,7 +3082,7 @@
(state/editing?) (state/editing?)
(keydown-up-down-handler direction) (keydown-up-down-handler direction)
(and (state/selection?) (== 1 (count (state/get-selection-blocks)))) (state/selection?)
(select-up-down direction) (select-up-down direction)
:else :else
@ -3108,34 +3111,35 @@
(defn open-selected-block! (defn open-selected-block!
[direction e] [direction e]
(when-let [block-id (some-> (state/get-selection-blocks) (let [selected-blocks (state/get-selection-blocks)
first f (case direction
(dom/attr "blockid") :left first
uuid)] :right last)]
(util/stop e) (when-let [block-id (some-> selected-blocks
(let [block {:block/uuid block-id} f
block-id (-> (state/get-selection-blocks) (dom/attr "blockid")
first uuid)]
(gobj/get "id") (util/stop e)
(string/replace "ls-block" "edit-block")) (let [block {:block/uuid block-id}
left? (= direction :left)] block-id (-> selected-blocks
(edit-block! block f
(if left? 0 :max) (gobj/get "id")
block-id)))) (string/replace "ls-block" "edit-block"))
left? (= direction :left)]
(edit-block! block
(if left? 0 :max)
block-id)))))
(defn shortcut-left-right [direction] (defn shortcut-left-right [direction]
(fn [e] (fn [e]
(when-not (auto-complete?) (when-not (auto-complete?)
(util/stop e)
(cond (cond
(state/editing?) (state/editing?)
(do (keydown-arrow-handler direction)
(util/stop e)
(keydown-arrow-handler direction))
(and (state/selection?) (== 1 (count (state/get-selection-blocks)))) (state/selection?)
(do (open-selected-block! direction e)
(util/stop e)
(open-selected-block! direction e))
:else :else
nil)))) nil))))