Skip to content

Commit e287f0d

Browse files
committed
fix(highlight): Do not let highlight exceed text range
1 parent 3f1d3f7 commit e287f0d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/highlight-support.js

Lines changed: 3 additions & 2 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 && text !== blockText.slice(actualStartIndex, actualEndIndex)) {

0 commit comments

Comments
 (0)