浏览代码

:art: https://github.com/Vanessa219/vditor/issues/1832

Vanessa 3 月之前
父节点
当前提交
880e57e523
共有 2 个文件被更改,包括 11 次插入4 次删除
  1. 2 0
      CHANGELOG.md
  2. 9 4
      src/ts/util/selection.ts

+ 2 - 0
CHANGELOG.md

@@ -28,6 +28,8 @@
 
 ### v3.11.2 / 2025-06
 
+* [改进列表内粘贴列表](https://github.com/Vanessa219/vditor/issues/1832) `改进功能`
+
 ### v3.11.1 / 2025-05-27
 
 * [支持德语](https://github.com/Vanessa219/vditor/pull/1816) `文档相关`

+ 9 - 4
src/ts/util/selection.ts

@@ -1,6 +1,6 @@
-import {Constants} from "../constants";
-import {isChrome} from "./compatibility";
-import {hasClosestBlock, hasClosestByClassName} from "./hasClosest";
+import { Constants } from "../constants";
+import { isChrome } from "./compatibility";
+import { hasClosestBlock, hasClosestByClassName, hasClosestByMatchTag } from "./hasClosest";
 
 export const getEditorRange = (vditor: IVditor) => {
     let range: Range;
@@ -262,7 +262,12 @@ export const insertHTML = (html: string, vditor: IVditor) => {
         if (!blockElement) {
             vditor[vditor.currentMode].element.insertAdjacentHTML("beforeend", pasteElement.innerHTML);
         } else {
-            blockElement.insertAdjacentHTML("afterend", pasteElement.innerHTML);
+            const liElement = hasClosestByMatchTag(range.startContainer, "LI");
+            if (liElement && pasteElement.firstElementChild.tagName === "UL") {
+                liElement.insertAdjacentHTML("afterend", pasteElement.firstElementChild.innerHTML);
+            } else {
+                blockElement.insertAdjacentHTML("afterend", pasteElement.innerHTML);
+            }
         }
         setRangeByWbr(vditor[vditor.currentMode].element, range);
     } else {