Skip to content

Commit

Permalink
🐛 fix #170
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Feb 25, 2020
1 parent de61123 commit 6696ca2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ts/wysiwyg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ class WYSIWYG {
pElement.textContent = node.textContent;
node.parentNode.insertBefore(pElement, node);
node.remove();
range.setStart(pElement.firstChild, startOffset);
range.setStart(pElement.firstChild, Math.min(pElement.firstChild.textContent.length, startOffset));
range.collapse(true);
return true;
} else if (!node.getAttribute("data-block")) {
Expand Down
7 changes: 6 additions & 1 deletion src/ts/wysiwyg/processKeydown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,12 @@ export const processKeydown = (vditor: IVditor, event: KeyboardEvent) => {

// shift+enter:软换行,但 table/hr/heading 处理、cell 内换行、block render 换行、li 软换行处理单独写在上面
if (!isCtrl(event) && event.shiftKey && !event.altKey && event.key === "Enter") {
range.insertNode(document.createTextNode("\n"));
if (["STRONG", "S", "STRONG", "I", "EM", "B"].includes(startContainer.parentElement.tagName)) {
// 行内元素软换行需继续 https://github.com/Vanessa219/vditor/issues/170
range.insertNode(document.createTextNode("\n" + Constants.ZWSP));
} else {
range.insertNode(document.createTextNode("\n"));
}
range.collapse(false);
setSelectionFocus(range);
afterRenderEvent(vditor);
Expand Down

0 comments on commit 6696ca2

Please sign in to comment.