mirror of
https://github.com/logseq/logseq.git
synced 2026-05-04 10:56:32 +00:00
refactor selection shortcut
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user