Browse Source

Enhance: don't move to the previous block when there's highlighted area and pressing `left`

Tienson Qin 4 years ago
parent
commit
6b249aa865
2 changed files with 9 additions and 2 deletions
  1. 3 2
      src/main/frontend/handler/editor.cljs
  2. 6 0
      src/main/frontend/util.cljc

+ 3 - 2
src/main/frontend/handler/editor.cljs

@@ -2369,8 +2369,9 @@
 
 (defn- on-arrow-move-to-boundray
   [state input e direction]
-  (when (or (and (= :left direction) (util/input-start? input))
-            (and (= :right direction) (util/input-end? input)))
+  (when (and (not (util/input-selected? input))
+             (or (and (= :left direction) (util/input-start? input))
+             (and (= :right direction) (util/input-end? input))))
     (move-to-block-when-cross-boundrary state e direction)))
 
 (defn keydown-arrow-handler

+ 6 - 0
src/main/frontend/util.cljc

@@ -765,6 +765,12 @@
           (= (count (.-value input))
              (.-selectionStart input)))))
 
+#?(:cljs
+   (defn input-selected?
+     [input]
+     (not= (.-selectionStart input)
+           (.-selectionEnd input))))
+
 #?(:cljs
     (defn get-selected-text
       []