You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
724 B

  1. 'use strict'
  2. module.exports = {
  3. /**
  4. * Set Input Selection
  5. * @param {DOMElement} input The input element
  6. * @param {number} startPos The starting position
  7. * @param {nunber} endPos The ending position
  8. */
  9. setInputSelection: (input, startPos, endPos) => {
  10. input.focus()
  11. if (typeof input.selectionStart !== 'undefined') {
  12. input.selectionStart = startPos
  13. input.selectionEnd = endPos
  14. } else if (document.selection && document.selection.createRange) {
  15. // IE branch
  16. input.select()
  17. var range = document.selection.createRange()
  18. range.collapse(true)
  19. range.moveEnd('character', endPos)
  20. range.moveStart('character', startPos)
  21. range.select()
  22. }
  23. }
  24. }