Skip to content

Commit 09e0bdb

Browse files
committed
fix: cleanup empty highlights
1 parent d2ef3eb commit 09e0bdb

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/highlight-support.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const highlightSupport = {
5151
marker.appendChild(fragment)
5252
range.deleteContents()
5353
range.insertNode(marker)
54+
highlightSupport.cleanupStaleMarkerNodes(editableHost, 'comment')
5455
return startIndex
5556
},
5657

@@ -115,6 +116,15 @@ const highlightSupport = {
115116
}
116117
},
117118

119+
cleanupStaleMarkerNodes (editableHost, highlightType) {
120+
editableHost.querySelectorAll('span[data-highlight="' + highlightType + '"]')
121+
.forEach(node => {
122+
if (!node.textContent.length) {
123+
node.parentNode.removeChild(node)
124+
}
125+
})
126+
},
127+
118128
createMarkerNode (markerMarkup, highlightType, win) {
119129
let marker = $(markerMarkup)[0]
120130

0 commit comments

Comments
 (0)