diff options
| author | mrmr1993 | 2015-02-19 14:46:17 +0000 |
|---|---|---|
| committer | mrmr1993 | 2015-02-19 14:47:19 +0000 |
| commit | eb7b8bea2ae2a7c4f49960f7d0807c75cb3250b3 (patch) | |
| tree | a7c54927e304a0f24c5a36f0717c182be08805f5 | |
| parent | 7a380f3f0db55aefadcf73cf41e942e44e22df79 (diff) | |
| download | vimium-eb7b8bea2ae2a7c4f49960f7d0807c75cb3250b3.tar.bz2 | |
Make DomUtils.isSelected behave correctly for all editable elements
| -rw-r--r-- | lib/dom_utils.coffee | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index 26e0e736..a68edd6c 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -167,20 +167,21 @@ DomUtils = node = node.parentNode false - # True if element contains the active selection range, or if the element does not support its selection - # being accessed. + # True if the current element is editable and contains the active selection range. isSelected: (element) -> if element.isContentEditable node = document.getSelection().anchorNode node and @isDOMDescendant element, node else - try - element.selectionStart != element.selectionEnd - 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 + selection = document.getSelection() + if selection.type == "Range" and selection.isCollapsed + # The selection is inside the Shadow DOM of a node. We can check the node it registers as being + # before, since this represents the node whose Shadow DOM it's inside. + containerNode = selection.anchorNode.childNodes[selection.anchorOffset] + + element == containerNode # True if the selection is inside the Shadow DOM of our element. + else + false simulateSelect: (element) -> # If element is already active, then we don't move the selection. However, we also won't get a new focus |
