diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/dom_utils.coffee | 14 | 
1 files changed, 14 insertions, 0 deletions
| diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index c1ce051f..9360bb95 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -236,6 +236,20 @@ DomUtils =      event.initTextEvent "textInput", true, true, null, text      element.dispatchEvent event +  # Adapted from: http://roysharon.com/blog/37. +  # This finds the element containing the selection focus. +  getElementWithFocus: (selection, backwards) -> +    r = t = selection.getRangeAt 0 +    if selection.type == "Range" +      r = t.cloneRange() +      r.collapse backwards +    t = r.startContainer +    t = t.childNodes[r.startOffset] if t.nodeType == 1 +    o = t +    o = o.previousSibling while o and o.nodeType != 1 +    t = o || t?.parentNode +    t +  extend DomUtils,    # From: https://github.com/component/textarea-caret-position/blob/master/index.js    getCaretCoordinates: do -> | 
