Skip to content

Commit

Permalink
🎨 fix #596
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Jul 20, 2020
1 parent e260a4c commit 491bb95
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

### v3.3.10 / 2020-07-xx

* [596](https://github.com/Vanessa219/vditor/issues/596) blockquote insdie ordered list `改进功能`
* [605](https://github.com/Vanessa219/vditor/issues/605) 块节点上下插入的优化 `改进功能`
* [602](https://github.com/Vanessa219/vditor/issues/602) Three enters inside codeblock `修复缺陷`
* [600](https://github.com/Vanessa219/vditor/issues/600) codeblock inside footnote `修复缺陷`
Expand Down
4 changes: 2 additions & 2 deletions demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ if (window.innerWidth < 768) {
}

window.vditor = new Vditor('vditor', {
// _lutePath: `http://192.168.0.107:9090/lute.min.js?${new Date().getTime()}`,
_lutePath: 'src/js/lute/lute.min.js',
_lutePath: `http://192.168.0.107:9090/lute.min.js?${new Date().getTime()}`,
// _lutePath: 'src/js/lute/lute.min.js',
toolbar,
mode: 'sv',
height: window.innerHeight + 100,
Expand Down
7 changes: 4 additions & 3 deletions src/ts/sv/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,21 @@ export const processPreviousMarkers = (spanElement: HTMLElement) => {
const previousType = previousElement.getAttribute("data-type");
if (previousType === "li-marker" || previousType === "blockquote-marker" || previousType === "task-marker" ||
previousType === "padding") {
const previousText = previousElement.textContent;
if (previousType === "li-marker" &&
(spanType === "code-block-open-marker" || spanType === "code-block-info")) {
// https://github.com/Vanessa219/vditor/issues/586
markerText = previousElement.textContent.replace(/\S/g, " ") + markerText;
markerText = previousText.replace(/\S/g, " ") + markerText;
} else if (spanType === "code-block-close-marker" &&
previousElement.nextElementSibling.isSameNode(spanElement)) {
// https://github.com/Vanessa219/vditor/issues/594
const openMarker = getSideByType(spanElement, "code-block-open-marker");
if (openMarker && openMarker.previousElementSibling) {
previousElement = openMarker.previousElementSibling;
markerText = previousElement.textContent + markerText;
markerText = previousText + markerText;
}
} else {
markerText = previousElement.textContent + markerText;
markerText = previousText + markerText;
}
} else if (previousType === "newline") {
hasNL = true;
Expand Down
16 changes: 14 additions & 2 deletions src/ts/sv/processKeydown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ export const processKeydown = (vditor: IVditor, event: KeyboardEvent) => {
textElement.previousElementSibling.getAttribute("data-type") === "blockquote-marker") {
blockquoteMarkerElement = textElement.previousElementSibling as HTMLElement;
}
// 回车逐个删除 marker 标记
// 回车逐个删除 blockquote marker 标记
if (blockquoteMarkerElement) {
if (event.key === "Enter" && !isCtrl(event) && !event.altKey &&
blockquoteMarkerElement.nextElementSibling.textContent.trim() === "" &&
getSelectPosition(blockquoteMarkerElement, vditor.sv.element, range).start ===
blockquoteMarkerElement.textContent.length) {
if (blockquoteMarkerElement.previousElementSibling?.getAttribute("data-type") === "padding") {
// 列表中存在多行 BQ 时,标记回车需跳出列表
blockquoteMarkerElement.previousElementSibling.setAttribute("data-action", "enter-remove");
}
blockquoteMarkerElement.remove();
processAfterRender(vditor);
event.preventDefault();
Expand Down Expand Up @@ -119,7 +123,15 @@ export const processKeydown = (vditor: IVditor, event: KeyboardEvent) => {
}
let newLineText = "\n";
if (spanElement) {
newLineText += processPreviousMarkers(spanElement);
if (spanElement.previousElementSibling?.getAttribute("data-action") === "enter-remove") {
// https://github.com/Vanessa219/vditor/issues/596
spanElement.previousElementSibling.remove();
processAfterRender(vditor);
event.preventDefault();
return true;
} else {
newLineText += processPreviousMarkers(spanElement);
}
}
range.insertNode(document.createTextNode(newLineText));
range.collapse(false);
Expand Down

0 comments on commit 491bb95

Please sign in to comment.