Skip to content

Commit

Permalink
Move type check
Browse files Browse the repository at this point in the history
  • Loading branch information
sydneyjodon-wk committed May 12, 2021
1 parent 70b2d82 commit 9efb5b1
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/utils/edit/selectionRange.ts
Expand Up @@ -96,6 +96,11 @@ export function setSelectionRange(
}
}

// Moving the selection inside <input> or <textarea> does not alter the document Selection.
if (isElementType(element, 'input') || isElementType(element, 'textarea')) {
return
}

const range = element.ownerDocument.createRange()
range.selectNodeContents(element)

Expand All @@ -107,13 +112,7 @@ export function setSelectionRange(

const selection = element.ownerDocument.getSelection()
// istanbul ignore else
if (
selection &&
// Skip setting the range for <input> and <textarea> because
// the parent <div> will be selected.
!isElementType(element, 'input') &&
!isElementType(element, 'textarea')
) {
if (selection) {
selection.removeAllRanges()
selection.addRange(range)
}
Expand Down

0 comments on commit 9efb5b1

Please sign in to comment.