diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/selection.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/util/selection.js b/src/util/selection.js new file mode 100644 index 0000000..395901e --- /dev/null +++ b/src/util/selection.js | |||
@@ -0,0 +1,17 @@ | |||
1 | export default function createSelection(field, start, end) { | ||
2 | if (field.createTextRange) { | ||
3 | const selRange = field.createTextRange(); | ||
4 | selRange.collapse(true); | ||
5 | selRange.moveStart('character', start); | ||
6 | selRange.moveEnd('character', end); | ||
7 | selRange.select(); | ||
8 | field.focus(); | ||
9 | } else if (field.setSelectionRange) { | ||
10 | field.focus(); | ||
11 | field.setSelectionRange(start, end); | ||
12 | } else if (typeof field.selectionStart !== 'undefined') { | ||
13 | field.selectionStart = start; | ||
14 | field.selectionEnd = end; | ||
15 | field.focus(); | ||
16 | } | ||
17 | } | ||