1
0
Эх сурвалжийг харах

fix: CTRL+X is deleting the last character when nothing is selected

fix #5821
Tienson Qin 3 жил өмнө
parent
commit
290c2b5b83

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

@@ -2957,14 +2957,18 @@
   "shortcut cut action:
   * when in selection mode, cut selected blocks
   * when in edit mode with text selected, cut selected text
-  * otherwise same as delete shortcut"
+  * otherwise nothing need to be handled."
   [e]
   (cond
     (state/selection?)
     (shortcut-cut-selection e)
 
-    (state/editing?)
-    (keydown-backspace-handler true e)))
+    (and (state/editing?) (util/input-text-selected?
+                           (gdom/getElement (state/get-edit-input-id))))
+    (keydown-backspace-handler true e)
+
+    :else
+    nil))
 
 (defn delete-selection
   [e]

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

@@ -312,6 +312,11 @@
   (when input
     (.-selectionEnd input)))
 
+(defn input-text-selected?
+  [input]
+  (not= (get-selection-start input)
+        (get-selection-end input)))
+
 (defn get-selection-direction
   [input]
   (when input