Skip to content

Commit f68d9e7

Browse files
authored
Merge pull request #161 from inokawa/index-size-error
Add guard to avoid IndexSizeError on selection change
2 parents 5a05324 + a72025c commit f68d9e7

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/utils.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @internal
33
*/
4-
export const { min } = Math;
4+
export const { min, max } = Math;
55

66
/**
77
* @internal

src/vendor/range-at-index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import { max } from "../utils";
2+
13
/**
24
* range-at-index
35
* https://github.com/webmodules/range-at-index/
46
* Nathan Rajlich
57
*
68
* Forked from version 1.0.4; includes the following modifications:
79
* 1) Change module.exports to export default.
10+
* 2) Fix for https://github.com/inokawa/rich-textarea/issues/160
811
**/
912

1013
/**
@@ -44,8 +47,8 @@ function RangeAtIndex(el, index, offset, range) {
4447
}
4548

4649
// update the range with the start and end offsets
47-
if (start.node) range.setStart(start.node, start.offset);
48-
if (end.node) range.setEnd(end.node, end.offset);
50+
if (start.node) range.setStart(start.node, max(start.offset, 0));
51+
if (end.node) range.setEnd(end.node, max(end.offset, 0));
4952

5053
return range;
5154
}

0 commit comments

Comments
 (0)