diff --git a/CHANGELOG.md b/CHANGELOG.md index a9196c20f..42e81f97b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ ### v3.0.6 / 2020-03-xx +* [240](https://github.com/Vanessa219/vditor/issues/240) multiple markdown at one line `修复缺陷` * [241](https://github.com/Vanessa219/vditor/issues/241) When editing the heading, not converted using the cursor key `修复缺陷` * [242](https://github.com/Vanessa219/vditor/issues/242) combined lists "+" and "-" `修复缺陷` * [243](https://github.com/Vanessa219/vditor/issues/243) can not delete the table with "backspace" `修复缺陷` diff --git a/src/ts/ir/input.ts b/src/ts/ir/input.ts index fa0178588..a9abe9cb7 100644 --- a/src/ts/ir/input.ts +++ b/src/ts/ir/input.ts @@ -5,14 +5,14 @@ import {getSelectPosition, setRangeByWbr} from "../util/selection"; import {processAfterRender, processCodeRender} from "./process"; export const input = (vditor: IVditor, range: Range) => { - Array.from(vditor.ir.element.querySelectorAll(".vditor-ir__node--expand")).forEach((item) => { - item.classList.remove("vditor-ir__node--expand"); - }); - let blockElement = hasClosestBlock(range.startContainer); - + let afterSpace = ""; // 前后可以输入空格,但是 insert html 中有换行需忽略(使用 wbr 标识) if (blockElement && !blockElement.querySelector("wbr")) { + if (isHrMD(blockElement.innerHTML) || isHeadingMD(blockElement.innerHTML)) { + return; + } + // 前后空格处理 const startOffset = getSelectPosition(blockElement, range).start; @@ -42,14 +42,21 @@ export const input = (vditor: IVditor, range: Range) => { } } - if (startSpace || endSpace || isHrMD(blockElement.innerHTML) || isHeadingMD(blockElement.innerHTML)) { - if (blockElement.classList.contains("vditor-ir__node")) { - blockElement.classList.add("vditor-ir__node--expand"); + if (startSpace || endSpace) { + const markerElement = hasClosestByClassName(range.startContainer, "vditor-ir__marker"); + if (markerElement && endSpace) { + // inline marker space https://github.com/Vanessa219/vditor/issues/239 + afterSpace = " "; + } else { + return; } - return; } } + Array.from(vditor.ir.element.querySelectorAll(".vditor-ir__node--expand")).forEach((item) => { + item.classList.remove("vditor-ir__node--expand"); + }); + if (!blockElement) { // 使用顶级块元素,应使用 innerHTML blockElement = vditor.ir.element; @@ -114,7 +121,7 @@ export const input = (vditor: IVditor, range: Range) => { } log("SpinVditorIRDOM", html, "argument", vditor.options.debugger); - html = vditor.lute.SpinVditorIRDOM(html); + html = vditor.lute.SpinVditorIRDOM(html) + afterSpace; log("SpinVditorIRDOM", html, "result", vditor.options.debugger); if (isIRElement) { diff --git a/src/ts/util/fixBrowserBehavior.ts b/src/ts/util/fixBrowserBehavior.ts index fbeadc9fd..5154e9ee2 100644 --- a/src/ts/util/fixBrowserBehavior.ts +++ b/src/ts/util/fixBrowserBehavior.ts @@ -36,7 +36,7 @@ const goPreviousCell = (cellElement: HTMLElement, range: Range, isSelected = tru range.collapse(false); } } - return previousElement + return previousElement; }; export const listToggle = (vditor: IVditor, range: Range, type: string, cancel = true) => { @@ -541,7 +541,7 @@ export const fixTable = (vditor: IVditor, event: KeyboardEvent, range: Range) => && range.startOffset === 0 && range.toString() === "") { const previousCellElement = goPreviousCell(cellElement, range, false); if (!previousCellElement && tableElement) { - tableElement.outerHTML = `