export function getSelection()

in src/lib/api/event.recorder.ts [302:323]


export function getSelection(node: HTMLInputElement): PrebootSelection {
  node = node || {} as HTMLInputElement;

  const nodeValue = node.value || '';
  const selection: PrebootSelection = {
    start: nodeValue.length,
    end: nodeValue.length,
    direction: 'forward'
  };

  // if browser support selectionStart on node (Chrome, FireFox, IE9+)
  try {
    if (node.selectionStart || node.selectionStart === 0) {
      selection.start = node.selectionStart;
      selection.end = node.selectionEnd ? node.selectionEnd : 0;
      selection.direction = node.selectionDirection ?
        node.selectionDirection as PrebootSelectionDirection : 'none';
    }
  } catch (ex) {}

  return selection;
}