Skip to content

Commit

Permalink
🎨 行内元素 #814
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Nov 17, 2020
1 parent c8b1d02 commit 75e7bc1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/assets/scss/_reset.scss
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@
&--hover {
background-color: rgb(250, 241, 209);
border-bottom: 2px solid rgb(255, 198, 10);

.vditor-comment {
border-bottom: 2px solid rgb(255, 198, 10);
}
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/ts/wysiwyg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,20 @@ class WYSIWYG {
const contents = range.cloneContents();
range.deleteContents();
contents.childNodes.forEach((item: HTMLElement) => {
let wrap = false
if (item.nodeType === 3) {
wrap = true
} else if (!item.classList.contains("vditor-comment")) {
wrap = true
} else if (item.classList.contains("vditor-comment")) {
item.setAttribute("data-cmtids", item.getAttribute("data-cmtids") + " " + id);
}
if (wrap) {
const commentElement = document.createElement("span");
commentElement.classList.add("vditor-comment");
commentElement.setAttribute("data-cmtids", id);
item.parentNode.insertBefore(commentElement, item);
commentElement.appendChild(item);
} else if (item.classList.contains("vditor-comment")) {
item.setAttribute("data-cmtids", item.getAttribute("data-cmtids") + " " + id);
}
});
range.insertNode(contents);
Expand Down

0 comments on commit 75e7bc1

Please sign in to comment.