From e82f64842baac444be262d0bbae4c414b6f218aa Mon Sep 17 00:00:00 2001 From: Van Date: Sat, 8 Feb 2020 11:49:10 +0800 Subject: [PATCH] :bug: fix #115 --- CHANGELOG.md | 1 + src/assets/scss/_wysiwyg.scss | 4 ++++ src/ts/wysiwyg/toolbarEvent.ts | 14 +++++++------- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f42532f5..2da8592b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ ### v2.1.11 / 2020-02-07 * [117](https://github.com/Vanessa219/vditor/issues/117) cursor moving problem near inline code `修复缺陷` +* [115](https://github.com/Vanessa219/vditor/issues/115) codeblock difference between ``` and ctrl+u `修复缺陷` * [112](https://github.com/Vanessa219/vditor/issues/112) 列表项加代码块问题 `修复缺陷` * [111](https://github.com/Vanessa219/vditor/issues/111) ctrl+b, ctrl+i, ctrl+s not working at starting and combining `修复缺陷` * [109](https://github.com/Vanessa219/vditor/issues/109) tab key at list `改进功能` diff --git a/src/assets/scss/_wysiwyg.scss b/src/assets/scss/_wysiwyg.scss index e2ae6817f..048818234 100644 --- a/src/assets/scss/_wysiwyg.scss +++ b/src/assets/scss/_wysiwyg.scss @@ -33,6 +33,10 @@ margin-bottom: 0; } + code { + padding: 0.2em 0.4em !important; + } + & > code { display: none; } diff --git a/src/ts/wysiwyg/toolbarEvent.ts b/src/ts/wysiwyg/toolbarEvent.ts index 3aac2b096..cb3663c73 100644 --- a/src/ts/wysiwyg/toolbarEvent.ts +++ b/src/ts/wysiwyg/toolbarEvent.ts @@ -246,17 +246,17 @@ export const toolbarEvent = (vditor: IVditor, actionBtn: Element) => { setCurrentToolbar(vditor.toolbar.elements, ["inline-code"]); } else if (commandName === "code") { const node = document.createElement("div"); - if (range.collapsed) { - node.className = "vditor-wysiwyg__block"; - node.setAttribute("data-type", "code-block"); - node.innerHTML = `
`; + node.className = "vditor-wysiwyg__block"; + node.setAttribute("data-type", "code-block"); + node.setAttribute("data-block", "0"); + node.setAttribute("data-marker", "```"); + if (range.toString() === "") { + node.innerHTML = `
`; range.insertNode(node); range.selectNodeContents(node.firstChild.firstChild); setSelectionFocus(range); } else { - node.className = "vditor-wysiwyg__block"; - node.setAttribute("data-type", "code-block"); - node.innerHTML = `
${range.toString()}
`; + node.innerHTML = `
${range.toString()}
`; range.deleteContents(); range.insertNode(node); range.selectNodeContents(node.firstChild.firstChild);