Liyuan Li 5 years ago
parent
commit
363c6c430a
3 changed files with 5 additions and 2 deletions
  1. 2 0
      CHANGELOG.md
  2. 2 1
      src/ts/ir/processKeydown.ts
  3. 1 1
      src/ts/util/fixBrowserBehavior.ts

+ 2 - 0
CHANGELOG.md

@@ -81,6 +81,8 @@
 
 ### v3.5.0 / 2020-08-xx
 
+* [730](https://github.com/Vanessa219/vditor/issues/730) 数学公式细节处理 `修复缺陷`
+
 ### v3.4.7 / 2020-08-22
 
 * [717](https://github.com/Vanessa219/vditor/issues/717) 在IR模式下插入特殊字符的bug `修复缺陷`

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

@@ -169,7 +169,8 @@ export const processKeydown = (vditor: IVditor, event: KeyboardEvent) => {
         }
 
         if (blockElement && blockElement.previousElementSibling
-            && blockElement.previousElementSibling.getAttribute("data-type") === "code-block") {
+            && (blockElement.previousElementSibling.getAttribute("data-type") === "code-block" ||
+                blockElement.previousElementSibling.getAttribute("data-type") === "math-block")) {
             const rangeStart = getSelectPosition(blockElement, vditor.ir.element, range).start;
             if (rangeStart === 0 || (rangeStart === 1 && blockElement.innerText.startsWith(Constants.ZWSP))) {
                 // 当前块删除后光标落于代码渲染块上,当前块会被删除,因此需要阻止事件,不能和 keyup 中的代码块处理合并

+ 1 - 1
src/ts/util/fixBrowserBehavior.ts

@@ -150,7 +150,7 @@ export const insertBeforeBlock = (vditor: IVditor, event: KeyboardEvent, range:
                                   blockElement: HTMLElement) => {
     const position = getSelectPosition(element, vditor[vditor.currentMode].element, range);
     if ((event.key === "ArrowUp" && element.textContent.substr(position.start).indexOf("\n") === -1) ||
-        ((event.key === "ArrowLeft" || event.key === "Backspace") && position.start === 0)) {
+        ((event.key === "ArrowLeft" || (event.key === "Backspace" && range.toString() === "")) && position.start === 0)) {
         const previousElement = blockElement.previousElementSibling;
         // table || code
         if (!previousElement ||