Skip to content

Commit

Permalink
🐛 empty, insert headings
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Mar 28, 2020
1 parent 556ba9c commit d736366
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/ts/ir/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const processCodeRender = (previewPanel: HTMLElement, vditor: IVditor) =>

export const processHeading = (vditor: IVditor, value: string) => {
const range = getSelection().getRangeAt(0);
const headingElement = hasClosestBlock(range.startContainer);
const headingElement = hasClosestBlock(range.startContainer) || range.startContainer as HTMLElement;
if (headingElement) {
if (value === "") {
const headingMarkerElement = headingElement.querySelector(".vditor-ir__marker--heading");
Expand Down Expand Up @@ -124,8 +124,8 @@ export const processToolbar = (vditor: IVditor, actionBtn: Element, prefix: stri
const range = getEditorRange(vditor.ir.element);
const commandName = actionBtn.getAttribute("data-type");
let typeElement = range.startContainer as HTMLElement;
if (range.startContainer.nodeType !== 3 && typeElement.classList.contains("vditor-reset")) {
typeElement = typeElement.childNodes[range.startOffset] as HTMLElement;
if (typeElement.nodeType === 3) {
typeElement = typeElement.parentElement;
}
// 移除
if (actionBtn.classList.contains("vditor-menu--current")) {
Expand Down Expand Up @@ -166,7 +166,11 @@ export const processToolbar = (vditor: IVditor, actionBtn: Element, prefix: stri
}

if (commandName === "line") {
typeElement.insertAdjacentHTML("afterend", '<hr data-block="0"><p data-block="0">\n<wbr></p>');
if (typeElement.classList.contains("vditor-reset")) {
typeElement.innerHTML = '<hr data-block="0"><p data-block="0">\n<wbr></p>';
} else {
typeElement.insertAdjacentHTML("afterend", '<hr data-block="0"><p data-block="0">\n<wbr></p>');
}
} else if (commandName === "quote") {
const blockElement = hasClosestBlock(range.startContainer);
if (blockElement) {
Expand Down

0 comments on commit d736366

Please sign in to comment.