diff options
| -rw-r--r-- | content_scripts/mode_find.coffee | 13 | ||||
| -rw-r--r-- | lib/dom_utils.coffee | 6 |
2 files changed, 8 insertions, 11 deletions
diff --git a/content_scripts/mode_find.coffee b/content_scripts/mode_find.coffee index 950b08e9..f19b5db4 100644 --- a/content_scripts/mode_find.coffee +++ b/content_scripts/mode_find.coffee @@ -6,7 +6,7 @@ class SuppressPrintable extends Mode constructor: (options) -> super options handler = (event) => if KeyboardUtils.isPrintable event then @suppressEvent else @continueBubbling - type = document.getSelection().type + type = DomUtils.getSelectionType() # We use unshift here, so we see events after normal mode, so we only see unmapped keys. @unshift @@ -16,7 +16,7 @@ class SuppressPrintable extends Mode keyup: (event) => # If the selection type has changed (usually, no longer "Range"), then the user is interacting with # the input element, so we get out of the way. See discussion of option 5c from #1415. - @exit() if document.getSelection().type != type + @exit() if DomUtils.getSelectionType() != type # When we use find, the selection/focus can land in a focusable/editable element. In this situation, special # considerations apply. We implement three special cases: @@ -235,17 +235,14 @@ class FindMode extends Mode getCurrentRange = -> selection = getSelection() - if selection.type == "None" + if DomUtils.getSelectionType(selection) == "None" range = document.createRange() range.setStart document.body, 0 range.setEnd document.body, 0 range else - selection.collapseToStart() if selection.type == "Range" - if selection.rangeCount > 0 - selection.getRangeAt 0 - else # Firefox returns a selection with no ranges and null anchor/focusNode in some situations. - null + selection.collapseToStart() if DomUtils.getSelectionType(selection) == "Range" + selection.getRangeAt 0 getLinkFromSelection = -> node = window.getSelection().anchorNode diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index b44f5f51..d8a5d203 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -219,7 +219,7 @@ DomUtils = node = selection.anchorNode node and @isDOMDescendant element, node else - if selection.type == "Range" and selection.isCollapsed + if DomUtils.getSelectionType(selection) == "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] @@ -364,7 +364,7 @@ DomUtils = handlerStack.suppressEvent # Polyfill for selection.type (which is not available in Firefox). - getSelectionType: (selection) -> + getSelectionType: (selection = document.getSelection()) -> selection.type or do -> if selection.rangeCount == 0 "None" @@ -377,7 +377,7 @@ DomUtils = # This finds the element containing the selection focus. getElementWithFocus: (selection, backwards) -> r = t = selection.getRangeAt 0 - if selection.type == "Range" + if DomUtils.getSelectionType(selection) == "Range" r = t.cloneRange() r.collapse backwards t = r.startContainer |
