瀏覽代碼

:art: fix https://github.com/Vanessa219/vditor/issues/729

Vanessa 1 年之前
父節點
當前提交
f06b1a3630
共有 3 個文件被更改,包括 12 次插入0 次删除
  1. 1 0
      CHANGELOG.md
  2. 6 0
      src/ts/ir/input.ts
  3. 5 0
      src/ts/wysiwyg/index.ts

+ 1 - 0
CHANGELOG.md

@@ -19,6 +19,7 @@
 
 
 ### v3.10.6 / 2024-09
 ### v3.10.6 / 2024-09
 
 
+* [井号后输入空格就渲染标题](https://github.com/Vanessa219/vditor/issues/729) `改进功能`
 * [ir 模式下标题删除报错](https://github.com/Vanessa219/vditor/issues/1666) `修复缺陷`
 * [ir 模式下标题删除报错](https://github.com/Vanessa219/vditor/issues/1666) `修复缺陷`
 * [升级 echarts 至 5.5.1](https://github.com/Vanessa219/vditor/issues/1664) `开发重构`
 * [升级 echarts 至 5.5.1](https://github.com/Vanessa219/vditor/issues/1664) `开发重构`
 * [添加 `insertMD` 方法](https://github.com/Vanessa219/vditor/issues/1640) `引入特性`
 * [添加 `insertMD` 方法](https://github.com/Vanessa219/vditor/issues/1640) `引入特性`

+ 6 - 0
src/ts/ir/input.ts

@@ -57,6 +57,12 @@ export const input = (vditor: IVditor, range: Range, ignoreSpace = false, event?
             }
             }
             return;
             return;
         }
         }
+
+        // https://github.com/Vanessa219/vditor/issues/729
+        if (endSpace && /^#{1,6} $/.test(blockElement.textContent)) {
+            endSpace = false;
+        }
+
         if (endSpace) {
         if (endSpace) {
             const markerElement = hasClosestByClassName(range.startContainer, "vditor-ir__marker");
             const markerElement = hasClosestByClassName(range.startContainer, "vditor-ir__marker");
             if (markerElement) {
             if (markerElement) {

+ 5 - 0
src/ts/wysiwyg/index.ts

@@ -380,6 +380,11 @@ class WYSIWYG {
                 }
                 }
             }
             }
 
 
+            // https://github.com/Vanessa219/vditor/issues/729
+            if (endSpace && /^#{1,6} $/.test(blockElement.textContent)) {
+                endSpace = false;
+            }
+
             const headingElement = hasClosestByHeadings(getSelection().getRangeAt(0).startContainer);
             const headingElement = hasClosestByHeadings(getSelection().getRangeAt(0).startContainer);
             if (headingElement && headingElement.textContent === "") {
             if (headingElement && headingElement.textContent === "") {
                 // heading 为空删除 https://github.com/Vanessa219/vditor/issues/150
                 // heading 为空删除 https://github.com/Vanessa219/vditor/issues/150