Liyuan Li 5 年之前
父节点
当前提交
3e636f139c
共有 7 个文件被更改,包括 29 次插入6 次删除
  1. 1 0
      CHANGELOG.md
  2. 1 0
      demo/index.html
  3. 2 0
      demo/index.js
  4. 7 4
      src/ts/ir/index.ts
  5. 5 1
      src/ts/ir/processKeydown.ts
  6. 8 0
      src/ts/util/fixBrowserBehavior.ts
  7. 5 1
      src/ts/wysiwyg/processKeydown.ts

+ 1 - 0
CHANGELOG.md

@@ -68,6 +68,7 @@
 
 ### v3.3.3 / 2020-06-xx
 
+* [508](https://github.com/Vanessa219/vditor/issues/508) 软键盘 bug `修复缺陷`
 * [504](https://github.com/Vanessa219/vditor/issues/504) 解决编辑器中 esc 推出 hint 和 options.esc 冲突 `修复缺陷`
 * [500](https://github.com/Vanessa219/vditor/issues/500) wysiwyg 模式下打字数学公式会闪 `改进功能`
 

+ 1 - 0
demo/index.html

@@ -39,6 +39,7 @@
             color: #4285f4;
         }
     </style>
+    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vconsole.min.js"></script>
 </head>
 <body>
 <h2>

+ 2 - 0
demo/index.js

@@ -1,6 +1,8 @@
 import Vditor from '../src/index'
 import '../src/assets/scss/index.scss'
 
+// new VConsole()
+
 let toolbar
 if (window.innerWidth < 768) {
   toolbar = [

+ 7 - 4
src/ts/ir/index.ts

@@ -77,14 +77,14 @@ class IR {
                 });
         }
 
-        this.element.addEventListener("compositionend", (event: InputEvent) => {
-            input(vditor, getSelection().getRangeAt(0).cloneRange());
-        });
-
         this.element.addEventListener("compositionstart", (event: InputEvent) => {
             this.composingLock = true;
         });
 
+        this.element.addEventListener("compositionend", (event: InputEvent) => {
+            input(vditor, getSelection().getRangeAt(0).cloneRange());
+        });
+
         this.element.addEventListener("input", (event: InputEvent) => {
             if (this.preventInput) {
                 this.preventInput = false;
@@ -183,6 +183,9 @@ class IR {
                     processHint(vditor);
                 }
                 expandMarker(range, vditor);
+            } else if (event.keyCode === 229 && event.code === "" && event.key === "Unidentified") {
+                // https://github.com/Vanessa219/vditor/issues/508 IR 删除到节点需展开
+                expandMarker(range, vditor);
             }
 
             const previewRenderElement = hasClosestByClassName(range.startContainer, "vditor-ir__preview");

+ 5 - 1
src/ts/ir/processKeydown.ts

@@ -3,7 +3,7 @@ import {isCtrl} from "../util/compatibility";
 import {
     fixBlockquote, fixCJKPosition,
     fixCodeBlock, fixCursorDownInlineMath,
-    fixDelete, fixFirefoxArrowUpTable, fixHR,
+    fixDelete, fixFirefoxArrowUpTable, fixGSKeyBackspace, fixHR,
     fixList,
     fixMarkdown,
     fixTab,
@@ -31,6 +31,10 @@ export const processKeydown = (vditor: IVditor, event: KeyboardEvent) => {
         vditor.irUndo.recordFirstWbr(vditor, event);
     }
 
+    if (!fixGSKeyBackspace(event, vditor)) {
+        return false;
+    }
+
     const range = getEditorRange(vditor.ir.element);
     const startContainer = range.startContainer;
 

+ 8 - 0
src/ts/util/fixBrowserBehavior.ts

@@ -28,6 +28,14 @@ import {
     setSelectionByPosition, setSelectionFocus,
 } from "./selection";
 
+// https://github.com/Vanessa219/vditor/issues/508 软键盘无法删除空块
+export const fixGSKeyBackspace = (event: KeyboardEvent, vditor: IVditor) => {
+    if (event.keyCode === 229 && event.code === "" && event.key === "Unidentified" && vditor.currentMode !== "sv") {
+        vditor[vditor.currentMode].composingLock = true;
+        return false;
+    }
+};
+
 // https://github.com/Vanessa219/vditor/issues/361
 export const fixCJKPosition = (range: Range, event: KeyboardEvent) => {
     if (event.key === "Enter" || event.key === "Tab" || event.key === "Backspace" || event.key.indexOf("Arrow") > -1

+ 5 - 1
src/ts/wysiwyg/processKeydown.ts

@@ -3,7 +3,7 @@ import {isCtrl, isFirefox} from "../util/compatibility";
 import {scrollCenter} from "../util/editorCommonEvent";
 import {
     fixBlockquote, fixCJKPosition,
-    fixCodeBlock, fixCursorDownInlineMath, fixDelete, fixFirefoxArrowUpTable, fixHR,
+    fixCodeBlock, fixCursorDownInlineMath, fixDelete, fixFirefoxArrowUpTable, fixGSKeyBackspace, fixHR,
     fixList,
     fixMarkdown,
     fixTab,
@@ -37,6 +37,10 @@ export const processKeydown = (vditor: IVditor, event: KeyboardEvent) => {
         vditor.wysiwygUndo.recordFirstWbr(vditor, event);
     }
 
+    if (!fixGSKeyBackspace(event, vditor)) {
+        return false;
+    }
+
     const range = getEditorRange(vditor.wysiwyg.element);
     const startContainer = range.startContainer;