diff --git a/CHANGELOG.md b/CHANGELOG.md index f3147ffce..0ceea8ee2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,7 @@ ### v3.3.11 / 2020-07-xx +* [616](https://github.com/Vanessa219/vditor/pull/616) fix: safari下选中文字添加标题文字会消失 `修复缺陷` * [615](https://github.com/Vanessa219/vditor/issues/615) 即时渲染模式下在safari中光标位置跳动 `修复缺陷` ### v3.3.10 / 2020-07-20 diff --git a/src/ts/ir/process.ts b/src/ts/ir/process.ts index ee38ec19e..022cf8933 100644 --- a/src/ts/ir/process.ts +++ b/src/ts/ir/process.ts @@ -80,14 +80,14 @@ export const processHeading = (vditor: IVditor, value: string) => { if (headingElement) { if (value === "") { const headingMarkerElement = headingElement.querySelector(".vditor-ir__marker--heading"); - const selection = window.getSelection(); - selection.selectAllChildren(headingMarkerElement) + range.selectNodeContents(headingMarkerElement); + setSelectionFocus(range); document.execCommand("delete"); } else { - const html = value + headingElement.innerText; - const selection = window.getSelection(); - selection.selectAllChildren(headingElement) - document.execCommand("insertHTML", false, html); + range.selectNodeContents(headingElement); + range.collapse(true); + setSelectionFocus(range); + document.execCommand("insertHTML", false, value); } highlightToolbarIR(vditor); renderToc(vditor);