From d6450ed2122c3bf539c9ea837d4423a69f043a68 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 28 Jan 2015 14:00:38 +0000 Subject: Visual/edit modes: fix some movements... Also, change how vim's "w" is implemented. Also some code-review/cleanup. Better dd and yy for gmail. --- lib/dom_utils.coffee | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib') 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 -> -- cgit v1.2.3