Browse Source

:bug: 粘贴时,光标位置错误

Liyuan Li 5 years ago
parent
commit
18e7c48887
2 changed files with 7 additions and 0 deletions
  1. 1 0
      CHANGELOG.md
  2. 6 0
      src/ts/util/fixBrowserBehavior.ts

+ 1 - 0
CHANGELOG.md

@@ -68,6 +68,7 @@
 
 ### v3.3.12 / 2020-07-xx
 
+* [608](https://github.com/Vanessa219/vditor/issues/608) 更新使用截图和演示动画 `文档相关`
 * [587](https://github.com/Vanessa219/vditor/issues/587) IR & SV 保留 Setext 风格标题 `改进功能`
 * [626](https://github.com/Vanessa219/vditor/issues/626) 去除 Setext 标题解析开关 `开发重构`
 * [451](https://github.com/Vanessa219/vditor/issues/451) IR 模式保留 Emoji 原始输入 `改进功能`

+ 6 - 0
src/ts/util/fixBrowserBehavior.ts

@@ -1339,11 +1339,17 @@ export const paste = (vditor: IVditor, event: ClipboardEvent & { target: HTMLEle
         const blockElement = hasClosestBlock(getEditorRange(vditor[vditor.currentMode].element).startContainer);
         if (blockElement) {
             // https://github.com/Vanessa219/vditor/issues/591
+            const range = getEditorRange(vditor[vditor.currentMode].element)
+            vditor[vditor.currentMode].element.querySelectorAll("wbr").forEach((wbr) => {
+                wbr.remove();
+            });
+            range.insertNode(document.createElement("wbr"));
             if (vditor.currentMode === "wysiwyg") {
                 blockElement.outerHTML = vditor.lute.SpinVditorDOM(blockElement.outerHTML);
             } else {
                 blockElement.outerHTML = vditor.lute.SpinVditorIRDOM(blockElement.outerHTML);
             }
+            setRangeByWbr(vditor[vditor.currentMode].element, range);
             vditor[vditor.currentMode].element.querySelectorAll(`.vditor-${vditor.currentMode}__preview[data-render='2']`)
                 .forEach((item: HTMLElement) => {
                     processCodeRender(item, vditor);