From bc53ec67500c6e1aa6688c7cf2ad529f7ba4a33c Mon Sep 17 00:00:00 2001 From: BeADre <34639100+BeADre@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:26:33 +0800 Subject: [PATCH] Merge pull request #616 from BeADre/dev MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix: safari下选中文字添加标题文字会消失 --- src/ts/ir/process.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ts/ir/process.ts b/src/ts/ir/process.ts index 062b29560..ee38ec19e 100644 --- a/src/ts/ir/process.ts +++ b/src/ts/ir/process.ts @@ -80,12 +80,14 @@ export const processHeading = (vditor: IVditor, value: string) => { if (headingElement) { if (value === "") { const headingMarkerElement = headingElement.querySelector(".vditor-ir__marker--heading"); - range.selectNodeContents(headingMarkerElement); + const selection = window.getSelection(); + selection.selectAllChildren(headingMarkerElement) document.execCommand("delete"); } else { - range.selectNodeContents(headingElement); - range.collapse(true); - document.execCommand("insertHTML", false, value); + const html = value + headingElement.innerText; + const selection = window.getSelection(); + selection.selectAllChildren(headingElement) + document.execCommand("insertHTML", false, html); } highlightToolbarIR(vditor); renderToc(vditor);