Liyuan Li 5 years ago
parent
commit
beaa0da3b3
4 changed files with 13 additions and 4 deletions
  1. 1 1
      CHANGELOG.md
  2. 1 1
      demo/index.js
  3. 9 1
      src/ts/sv/inputEvent.ts
  4. 2 1
      src/ts/sv/process.ts

+ 1 - 1
CHANGELOG.md

@@ -79,11 +79,11 @@
 
 ### v3.4.0 / 2020-07-xx
 
+* [636](https://github.com/Vanessa219/vditor/issues/636) SV 模式 Setext 标题问题 `修复缺陷`
 * [639](https://github.com/Vanessa219/vditor/issues/639) 列表嵌套代码块后输入中文的问题 `修复缺陷`
 * [641](https://github.com/Vanessa219/vditor/issues/641) 清空 undo 栈后,第一次编辑操作无法进行记录 `修复缺陷`
 * [640](https://github.com/Vanessa219/vditor/issues/640) options.icon 无法进行切换 `改进功能`
 * [638](https://github.com/Vanessa219/vditor/pull/638) ir模式下图片编辑时很难触发md图片代码显示 `改进功能`
-* [636](https://github.com/Vanessa219/vditor/issues/636) SV 模式 Setext 标题问题 `修复缺陷`
 
 ### v3.3.12 / 2020-07-28
 

+ 1 - 1
demo/index.js

@@ -53,7 +53,7 @@ window.vditor = new Vditor('vditor', {
   _lutePath: `http://192.168.0.107:9090/lute.min.js?${new Date().getTime()}`,
   // _lutePath: 'src/js/lute/lute.min.js',
   toolbar,
-  // mode: 'sv',
+  mode: 'sv',
   height: window.innerHeight + 100,
   outline: true,
   debugger: true,

+ 9 - 1
src/ts/sv/inputEvent.ts

@@ -32,8 +32,9 @@ export const inputEvent = (vditor: IVditor, event?: InputEvent) => {
             processAfterRender(vditor);
             return;
         }
-        // https://github.com/Vanessa219/vditor/issues/584
+
         if (event.inputType === "deleteContentBackward") {
+            // https://github.com/Vanessa219/vditor/issues/584 代码块 marker 删除
             const codeBlockMarkerElement =
                 hasClosestByAttribute(startContainer, "data-type", "code-block-open-marker") ||
                 hasClosestByAttribute(startContainer, "data-type", "code-block-close-marker");
@@ -65,6 +66,13 @@ export const inputEvent = (vditor: IVditor, event?: InputEvent) => {
                     item.remove();
                 }
             });
+
+            // 标题删除
+            const headingElement = hasClosestByAttribute(startContainer, "data-type", "heading-marker");
+            if (headingElement && headingElement.textContent.indexOf("#") === -1) {
+                processAfterRender(vditor);
+                return;
+            }
         }
         // 删除或空格不解析,否则会 format 回去
         if ((event.data === " " || event.inputType === "deleteContentBackward") &&

+ 2 - 1
src/ts/sv/process.ts

@@ -59,7 +59,8 @@ export const processSpinVditorSVDOM = (html: string, vditor: IVditor) => {
 export const processPreviousMarkers = (spanElement: HTMLElement) => {
     const spanType = spanElement.getAttribute("data-type");
     let previousElement = spanElement.previousElementSibling;
-    let markerText = (spanType && spanType !== "text") ? spanElement.textContent : ""; // 有内容的子列表,在其 marker 后换行
+    // 有内容的子列表/标题,在其 marker 后换行
+    let markerText = (spanType && spanType !== "text" && spanType !== "heading-marker") ? spanElement.textContent : "";
     let hasNL = false;
     while (previousElement && !hasNL) {
         const previousType = previousElement.getAttribute("data-type");