Skip to content

Commit

Permalink
🐛 fix #42
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Jan 7, 2020
1 parent ed0c5a4 commit a430abf
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

### v2.0.13 / 2020-01-06

* [42](https://github.com/Vanessa219/vditor/issues/42) 在内联数学公式前进行删除操作会删除公式 `修复缺陷`
* [43](https://github.com/Vanessa219/vditor/issues/43) When copy & paste the link `修复缺陷`
* [39](https://github.com/Vanessa219/vditor/issues/39) 所见即所得模式录音bug `修复缺陷`
* [38](https://github.com/Vanessa219/vditor/issues/38) 有序列表顺序错误 `修复缺陷`
Expand Down
2 changes: 1 addition & 1 deletion src/ts/wysiwyg/addP2Li.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const addP2Li = (listElement: Element) => {
tempNodes.forEach((nodeItem) => {
pElement.appendChild(nodeItem);
});
node.insertAdjacentElement('beforebegin', pElement)
node.insertAdjacentElement("beforebegin", pElement);
tempNodes = [];
}

Expand Down
12 changes: 5 additions & 7 deletions src/ts/wysiwyg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,12 @@ class WYSIWYG {
range.selectNodeContents(previewElement.previousElementSibling.firstElementChild);
range.collapse(false);
} else {
if (blockRenderElement.nextElementSibling &&
blockRenderElement.nextElementSibling.classList.contains("vditor-wysiwyg__block")) {
const nextNode = blockRenderElement.nextSibling as HTMLElement;
if (nextNode && nextNode.nodeType !== 3 &&
nextNode.classList.contains("vditor-wysiwyg__block")) {
// 下一节点依旧为代码渲染块
(blockRenderElement.nextElementSibling
.querySelector(".vditor-wysiwyg__preview") as HTMLElement).click();
range.setStart(
blockRenderElement.nextElementSibling.firstElementChild.firstElementChild.firstChild,
0);
(nextNode.querySelector(".vditor-wysiwyg__preview") as HTMLElement).click();
range.setStart(nextNode.firstElementChild.firstElementChild.firstChild, 0);
} else {
// 跳过渲染块,光标移动到下一个节点
range.setStartAfter(blockRenderElement);
Expand Down
10 changes: 10 additions & 0 deletions src/ts/wysiwyg/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ export const input = (event: IHTMLInputEvent, vditor: IVditor, range: Range) =>
const wbrNode = document.createElement("wbr");
range.insertNode(wbrNode);

// 修正光标位于 math inline 第0个字符时,按下删除按钮 code 中内容会被删除
blockElement.querySelectorAll('.vditor-wysiwyg__block[data-type="math-inline"]').forEach((math) => {
if (!math.querySelector("code")) {
const previewElement = math.querySelector(".vditor-wysiwyg__preview");
previewElement.insertAdjacentHTML("beforebegin", `<code data-type="math-inline">${
math.querySelector(".vditor-math").getAttribute("data-math")}</code>`);
}
});

let vditorHTML;
if (blockElement.isEqualNode(vditor.wysiwyg.element)) {
vditorHTML = blockElement.innerHTML;
Expand All @@ -84,6 +93,7 @@ export const input = (event: IHTMLInputEvent, vditor: IVditor, range: Range) =>
}
}
}

// 合并多个 em, strong,s。以防止多个相同元素在一起时不满足 commonmark 规范,出现标记符
vditorHTML = vditorHTML.replace(/<\/strong><strong data-marker="\W{2}">/g, "")
.replace(/<\/em><em data-marker="\W{1}">/g, "")
Expand Down
4 changes: 2 additions & 2 deletions src/ts/wysiwyg/processCodeRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export const processCodeRender = (blockElement: HTMLElement, vditor: IVditor) =>
previewPanel.setAttribute("data-render", "false");
const showCode = () => {
const range = codeElement.ownerDocument.createRange();
if (codeElement.parentElement.tagName !== "PRE") {
if (codeElement.parentElement && codeElement.parentElement.tagName !== "PRE") {
codeElement.style.display = "inline";
range.selectNodeContents(codeElement);
range.setStart(codeElement.firstChild, 1);
} else {
codeElement.parentElement.style.display = "block";
if (!codeElement.firstChild) {
Expand Down

0 comments on commit a430abf

Please sign in to comment.