Skip to content

Commit

Permalink
Merge pull request #616 from BeADre/dev
Browse files Browse the repository at this point in the history
fix: safari下选中文字添加标题文字会消失
  • Loading branch information
BeADre authored Jul 23, 2020
1 parent f1f6adb commit bc53ec6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/ts/ir/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit bc53ec6

Please sign in to comment.