aboutsummaryrefslogblamecommitdiffhomepage
path: root/src/util/selection.js
blob: 395901e3a2e13c5e08dd6d5e8530daadaa2b9a80 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
















                                                            
export default function createSelection(field, start, end) {
  if (field.createTextRange) {
    const selRange = field.createTextRange();
    selRange.collapse(true);
    selRange.moveStart('character', start);
    selRange.moveEnd('character', end);
    selRange.select();
    field.focus();
  } else if (field.setSelectionRange) {
    field.focus();
    field.setSelectionRange(start, end);
  } else if (typeof field.selectionStart !== 'undefined') {
    field.selectionStart = start;
    field.selectionEnd = end;
    field.focus();
  }
}