mirror of https://github.com/logseq/logseq
refactor: selection state
parent
c7efda6c62
commit
d05c540c15
|
@ -268,8 +268,7 @@
|
|||
:left (str client-x "px")
|
||||
:top (str (+ scroll-y client-y) "px")))))
|
||||
|
||||
(and (state/in-selection-mode?)
|
||||
(seq (state/get-selection-blocks)))
|
||||
(state/selection?)
|
||||
(do
|
||||
(util/stop e)
|
||||
(let [client-x (gobj/get e "clientX")
|
||||
|
|
|
@ -1082,21 +1082,21 @@
|
|||
(exit-editing-and-set-selected-blocks! [(gdom/getElement (state/get-editing-block-dom-id))])
|
||||
|
||||
;; when selection and one block selected, select next block
|
||||
(and (state/in-selection-mode?) (== 1 (count (state/get-selection-blocks))))
|
||||
(and (state/selection?) (== 1 (count (state/get-selection-blocks))))
|
||||
(let [f (if (= :up direction) util/get-prev-block util/get-next-block)
|
||||
element (f (first (state/get-selection-blocks)))]
|
||||
(when element
|
||||
(state/conj-selection-block! element direction)))
|
||||
|
||||
;; if same direction, keep conj on same direction
|
||||
(and (state/in-selection-mode?) (= direction (state/get-selection-direction)))
|
||||
(and (state/selection?) (= direction (state/get-selection-direction)))
|
||||
(let [f (if (= :up direction) util/get-prev-block util/get-next-block)
|
||||
element (f (last (state/get-selection-blocks)))]
|
||||
(when element
|
||||
(state/conj-selection-block! element direction)))
|
||||
|
||||
;; if different direction, keep clear until one left
|
||||
(state/in-selection-mode?)
|
||||
(state/selection?)
|
||||
(clear-last-selected-block!))))
|
||||
|
||||
(defn save-block-aux!
|
||||
|
@ -2384,7 +2384,7 @@
|
|||
* when in edit mode with text selected, copy selected text as normal"
|
||||
[e]
|
||||
(cond
|
||||
(and (state/in-selection-mode?) (seq (state/get-selection-blocks)))
|
||||
(state/selection?)
|
||||
(shortcut-copy-selection e)
|
||||
|
||||
(state/editing?)
|
||||
|
@ -2404,7 +2404,7 @@
|
|||
[state-fn]
|
||||
(fn [e]
|
||||
(cond
|
||||
(and (state/in-selection-mode?) (seq (state/get-selection-blocks)))
|
||||
(state/selection?)
|
||||
(shortcut-cut-selection e)
|
||||
|
||||
(state/editing?)
|
||||
|
@ -2414,7 +2414,7 @@
|
|||
[state-fn]
|
||||
(fn [e]
|
||||
(cond
|
||||
(and (state/in-selection-mode?) (seq (state/get-selection-blocks)))
|
||||
(state/selection?)
|
||||
(shortcut-delete-selection e)
|
||||
|
||||
(state/editing?)
|
||||
|
|
|
@ -549,6 +549,11 @@
|
|||
[]
|
||||
(:selection/mode @state))
|
||||
|
||||
(defn selection?
|
||||
"True sense of selection mode with valid selected block"
|
||||
[]
|
||||
(and (in-selection-mode?) (seq (get-selection-blocks))))
|
||||
|
||||
(defn conj-selection-block!
|
||||
[block direction]
|
||||
(dom/add-class! block "selected noselect")
|
||||
|
|
Loading…
Reference in New Issue