enhance(ux): shift select after esc

This commit is contained in:
Tienson Qin
2022-06-16 05:49:59 +08:00
parent 55bd894230
commit a79880eb83
4 changed files with 29 additions and 22 deletions

View File

@@ -281,7 +281,7 @@
(p/let [_ (draw/create-draw-with-default-content path)]
(println "draw file created, " path))
text)) "Draw a graph with Excalidraw"]
["Embed HTML " (->inline "html")]
["Embed Video URL" [[:editor/input "{{video }}" {:last-pattern (state/get-editor-command-trigger)
@@ -405,25 +405,26 @@
:as _option}]
(let [selected? (not (string/blank? selected))
input (gdom/getElement id)
edit-content (gobj/get input "value")
current-pos (cursor/pos input)
prefix (subs edit-content 0 current-pos)
postfix (if selected?
(string/replace-first (subs edit-content current-pos)
selected
"")
(subs edit-content current-pos))
new-value (str prefix value postfix)
new-pos (- (+ (count prefix)
(count value)
(or forward-pos 0))
(or backward-pos 0))]
(state/set-block-content-and-last-pos! id new-value new-pos)
(cursor/move-cursor-to input new-pos)
(when selected?
(.setSelectionRange input new-pos (+ new-pos (count selected))))
(when check-fn
(check-fn new-value (dec (count prefix))))))
edit-content (gobj/get input "value")]
(when-not (string/blank? edit-content)
(let [current-pos (cursor/pos input)
prefix (subs edit-content 0 current-pos)
postfix (if selected?
(string/replace-first (subs edit-content current-pos)
selected
"")
(subs edit-content current-pos))
new-value (str prefix value postfix)
new-pos (- (+ (count prefix)
(count value)
(or forward-pos 0))
(or backward-pos 0))]
(state/set-block-content-and-last-pos! id new-value new-pos)
(cursor/move-cursor-to input new-pos)
(when selected?
(.setSelectionRange input new-pos (+ new-pos (count selected))))
(when check-fn
(check-fn new-value (dec (count prefix))))))))
(defn delete-pair!
[id]

View File

@@ -1927,7 +1927,7 @@
(when (contains? #{1 0} button)
(when-not (target-forbidden-edit? target)
(cond
(and shift? (state/get-selection-start-block))
(and shift? (state/get-selection-start-block-or-first))
(editor-handler/highlight-selection-area! block-id)
shift?

View File

@@ -1210,7 +1210,7 @@
(defn highlight-selection-area!
[end-block]
(when-let [start-block (state/get-selection-start-block)]
(when-let [start-block (state/get-selection-start-block-or-first)]
(let [blocks (util/get-nodes-between-two-nodes start-block end-block "ls-block")
direction (util/get-direction-between-two-nodes start-block end-block "ls-block")

View File

@@ -700,6 +700,12 @@
(uuid id)))
(distinct)))
(defn get-selection-start-block-or-first
[]
(or (get-selection-start-block)
(some-> (first (get-selection-blocks))
(gobj/get "id"))))
(defn in-selection-mode?
[]
(:selection/mode @state))