diff options
| author | mrmr1993 | 2015-02-17 23:10:49 +0000 |
|---|---|---|
| committer | mrmr1993 | 2015-02-17 23:16:48 +0000 |
| commit | 41626cdd7a52cb3595153e54f3f8c0c332373bb7 (patch) | |
| tree | a46ba55a3f7a4bc8ce048d7e165b774bd4edf8f4 /lib/dom_utils.coffee | |
| parent | 7cedc5d2481f61f4b0d1cbf99fbd203bb5c68b54 (diff) | |
| download | vimium-41626cdd7a52cb3595153e54f3f8c0c332373bb7.tar.bz2 | |
Guard against input elements which don't support selectionStart/End
These elements throw an error on access, meaning that we can't do an
existence check.
Diffstat (limited to 'lib/dom_utils.coffee')
| -rw-r--r-- | lib/dom_utils.coffee | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index 2ae9412e..83fb045c 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -167,7 +167,8 @@ DomUtils = node = node.parentNode false - # True if element contains the active selection range. + # True if element contains the active selection range, or if the element does not support its selection + # being accessed. isSelected: (element) -> if element.isContentEditable node = document.getSelection()?.anchorNode @@ -175,7 +176,13 @@ DomUtils = else # Note. This makes the wrong decision if the user has placed the caret at the start of element. We # cannot distinguish that case from the user having made no selection. - element.selectionStart? and element.selectionEnd? and element.selectionEnd != 0 + try + element.selectionEnd != 0 + catch + # This input element doesn't support selectionStart/selectionEnd. + # NOTE(mrmr1993): We choose true here because it does the right thing everywhere in the code. I am + # not certain that this is necessarily what we should do. + true simulateSelect: (element) -> # If element is already active, then we don't move the selection. However, we also won't get a new focus |
