refactor selection shortcut

This commit is contained in:
Weihua Lu
2021-04-09 18:09:20 +08:00
committed by Tienson Qin
parent 0b1f2f7cc4
commit d187b767b5
4 changed files with 58 additions and 95 deletions

View File

@@ -93,6 +93,9 @@
:selection/mode false
:selection/blocks []
:selection/start-block nil
;; either :up or :down, defaults to down
;; used to determine selection direction when two or more blocks are selected
:selection/direction :down
:custom-context-menu/show? false
:custom-context-menu/links nil
@@ -507,12 +510,14 @@
(get @state :selection/start-block))
(defn set-selection-blocks!
[blocks]
(when (seq blocks)
(swap! state assoc
:selection/mode true
:selection/blocks blocks)))
([blocks]
(set-selection-blocks! blocks :down))
([blocks direction]
(when (seq blocks)
(swap! state assoc
:selection/mode true
:selection/blocks blocks
:selection/direction direction))))
(defn into-selection-mode!
[]
(swap! state assoc :selection/mode true))
@@ -522,7 +527,7 @@
(swap! state assoc
:selection/mode false
:selection/blocks nil
:selection/up? nil))
:selection/direction :down))
(defn clear-selection-blocks!
[]
@@ -537,28 +542,24 @@
(:selection/mode @state))
(defn conj-selection-block!
[block up?]
[block direction]
(dom/add-class! block "selected noselect")
(swap! state assoc
:selection/mode true
:selection/blocks (conj (:selection/blocks @state) block)
:selection/up? up?))
:selection/direction direction))
(defn pop-selection-block!
(defn drop-last-selection-block!
[]
(let [[first-block & others] (:selection/blocks @state)]
(let [last-block (peek (:selection/blocks @state))]
(swap! state assoc
:selection/mode true
:selection/blocks others)
first-block))
:selection/blocks (vec (pop (:selection/blocks @state))))
last-block))
(defn selection-up?
(defn get-selection-direction
[]
(:selection/up? @state))
(defn set-selection-up!
[value]
(swap! state assoc :selection/up? value))
(:selection/direction @state))
(defn show-custom-context-menu!
[links]