Van 5 years ago
parent
commit
f985555464
5 changed files with 38 additions and 7 deletions
  1. 2 1
      CHANGELOG.md
  2. 1 1
      demo/index.js
  3. 6 0
      src/assets/scss/_ir.scss
  4. 27 3
      src/ts/ir/input.ts
  5. 2 2
      src/ts/markdown/md2html.ts

+ 2 - 1
CHANGELOG.md

@@ -57,7 +57,8 @@
 
 * [220](https://github.com/Vanessa219/vditor/issues/220) 软换行前进行删除,将会变为 p `修复缺陷`
 * [221](https://github.com/Vanessa219/vditor/issues/221) 输入复选框时出现乱码 `修复缺陷`
-* [222](https://github.com/Vanessa219/vditor/issues/222) The cursor does not enter when added in the middle of the list. `修复缺陷`
+* [222](https://github.com/Vanessa219/vditor/issues/222) The cursor does not enter when added in the middle of the list `修复缺陷`
+* [223](https://github.com/Vanessa219/vditor/issues/223) 下列 a 前输入 ``` b 会消失,且返回无光标 `修复缺陷`
 * 文档更新
   * 修改 `options.mode` 可选值为:'sv', 'wysiwyg', 'ir'
   * toolbar 中的 wysiwyg 修改为 'edit-mode'

+ 1 - 1
demo/index.js

@@ -3,7 +3,7 @@ import '../src/assets/scss/index.scss'
 window.vditor = new Vditor('vditor', {
   debugger: true,
   typewriterMode: true,
-  // mode: 'ir',
+  mode: 'ir',
   placeholder: 'placeholder',
   preview: {
     markdown: {

+ 6 - 0
src/assets/scss/_ir.scss

@@ -24,6 +24,11 @@
     }
   }
 
+  &__link {
+    color: $blurColor;
+    text-decoration: underline;
+  }
+
   .vditor-reset {
     background-color: var(--panel-background-color);
     margin: 0;
@@ -53,6 +58,7 @@
     }
   }
 
+  // block title
   h1:before,
   h2:before,
   h3:before,

+ 27 - 3
src/ts/ir/input.ts

@@ -1,12 +1,36 @@
+import {hasClosestBlock} from "../util/hasClosest";
 import {log} from "../util/log";
 import {setRangeByWbr} from "../wysiwyg/setRangeByWbr";
 import {processAfterRender} from "./process";
 
 export const input = (vditor: IVditor, range: Range) => {
     range.insertNode(document.createElement("wbr"));
-    log("SpinVditorIRDOM", vditor.ir.element.innerHTML, "argument", vditor.options.debugger);
-    vditor.ir.element.innerHTML = vditor.lute.SpinVditorIRDOM(vditor.ir.element.innerHTML);
-    log("SpinVditorIRDOM", vditor.ir.element.innerHTML, "result", vditor.options.debugger);
+
+    let blockElement = hasClosestBlock(range.startContainer);
+
+    if (!blockElement) {
+        // 使用顶级块元素,应使用 innerHTML
+        blockElement = vditor.ir.element;
+    }
+
+    const isIRElement = blockElement.isEqualNode(vditor.ir.element);
+    let html = "";
+    if (!isIRElement) {
+        html = blockElement.outerHTML;
+    } else {
+        html = blockElement.innerHTML;
+    }
+
+    log("SpinVditorIRDOM", html, "argument", vditor.options.debugger);
+    html = vditor.lute.SpinVditorIRDOM(html);
+    log("SpinVditorIRDOM", html, "result", vditor.options.debugger);
+
+    if (isIRElement) {
+        blockElement.innerHTML = html;
+    } else {
+        blockElement.outerHTML = html;
+    }
+
     setRangeByWbr(vditor.ir.element, range);
     processAfterRender(vditor, {
         enableAddUndoStack: true,

+ 2 - 2
src/ts/markdown/md2html.ts

@@ -9,8 +9,8 @@ export const loadLuteJs = (vditor: IVditor | string) => {
     //     cdn = vditor.options.cdn;
     // }
     // addScript(`${cdn}/dist/js/lute/lute.min.js`, "vditorLuteScript");
-    addScript(`/src/js/lute/lute.min.js`, "vditorLuteScript");
-    // addScript(`http://192.168.2.248:9090/lute.min.js?${new Date().getTime()}`, "vditorLuteScript");
+    // addScript(`/src/js/lute/lute.min.js`, "vditorLuteScript");
+    addScript(`http://192.168.2.248:9090/lute.min.js?${new Date().getTime()}`, "vditorLuteScript");
 
     if (vditor && typeof vditor === "object" && !vditor.lute) {
         vditor.lute = Lute.New();