aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dom_utils.coffee
diff options
context:
space:
mode:
authormrmr19932015-06-03 00:52:28 +0100
committermrmr19932015-06-10 17:26:52 +0100
commit7d75b770f65b9ed0c95f694ac2dd59e185fd6a4f (patch)
tree28505c1aec926eee027410e9677a2d020987bef4 /lib/dom_utils.coffee
parent915700fdf846fb1e5cc1ce71e51600257051e1a3 (diff)
downloadvimium-7d75b770f65b9ed0c95f694ac2dd59e185fd6a4f.tar.bz2
Move finding the element at a selection's focus to a library function
Diffstat (limited to 'lib/dom_utils.coffee')
-rw-r--r--lib/dom_utils.coffee12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index 7c47179c..9658df2b 100644
--- a/lib/dom_utils.coffee
+++ b/lib/dom_utils.coffee
@@ -326,6 +326,18 @@ DomUtils =
document.body.removeChild div
coordinates
+ getSelectionFocusElement: ->
+ sel = window.getSelection()
+ if not sel.focusNode?
+ null
+ else if sel.focusNode == sel.anchorNode and sel.focusOffset == sel.anchorOffset
+ # The selection either *is* an element, or is inside an opaque element (eg. <input>).
+ sel.focusNode.childNodes[sel.focusOffset]
+ else if sel.focusNode.nodeType != sel.focusNode.ELEMENT_NODE
+ sel.focusNode.parentElement
+ else
+ sel.focusNode
+
# Get the text content of an element (and its descendents), but omit the text content of previously-visited
# nodes. See #1514.
# NOTE(smblott). This is currently O(N^2) (when called on N elements). An alternative would be to mark