Skip to content

Commit 5a5d397

Browse files
committed
fix(highlight): Do not let highlight exceed text range
1 parent 3558b83 commit 5a5d397

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/highlight-support.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ const highlightSupport = {
4545
this.win
4646
)
4747

48-
const actualStartIndex = startIndex
49-
const actualEndIndex = endIndex
48+
// Do not let highlight exceed text range
49+
const actualStartIndex = Math.min(Math.max(startIndex, 0), blockText.length - 1)
50+
const actualEndIndex = Math.min(Math.max(endIndex, 1), blockText.length)
5051

5152
// If text is provided then validate that it matches
5253
if (text) {
@@ -116,7 +117,7 @@ const highlightSupport = {
116117
if (position) res[highlightId] = position
117118
}
118119

119-
return res
120+
return Object.keys(res).length > 0 ? res : undefined
120121
},
121122

122123
extractMarkerNodePosition (editableHost, markers) {

0 commit comments

Comments
 (0)