Skip to content

Commit

Permalink
🐛 fix Vanessa219#240
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 authored and stevapple committed Apr 8, 2020
1 parent d7ddd85 commit 90cf4e5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" `修复缺陷`
Expand Down
27 changes: 17 additions & 10 deletions src/ts/ir/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/ts/util/fixBrowserBehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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 = `<p data-block="0"><wbr>${tableElement.textContent}</p>`
tableElement.outerHTML = `<p data-block="0"><wbr>${tableElement.textContent}</p>`;
setRangeByWbr(vditor[vditor.currentMode].element, range);
execAfterRender(vditor);
}
Expand Down

0 comments on commit 90cf4e5

Please sign in to comment.