aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-03-06 11:46:26 +0000
committerStephen Blott2015-03-06 11:46:26 +0000
commitb959fa5c6b36ba19340f195d822b4b3cca8ccd2d (patch)
tree133821233fea7262f2235647a788fc22c085643c
parent0bda93d8ba36e64d7759d2f4e4f2965a3312425d (diff)
downloadvimium-b959fa5c6b36ba19340f195d822b4b3cca8ccd2d.tar.bz2
Cosmetic changes (following #1490).
Mainly fix the indentation on comments. Also tweak wording a bid.
-rw-r--r--lib/dom_utils.coffee24
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index 3633b285..707906b4 100644
--- a/lib/dom_utils.coffee
+++ b/lib/dom_utils.coffee
@@ -167,18 +167,17 @@ DomUtils =
node = node.parentNode
false
- # True if the current element is editable and contains the active selection range.
+ # True if element is editable and contains the active selection range.
isSelected: (element) ->
+ selection = document.getSelection()
if element.isContentEditable
- node = document.getSelection().anchorNode
+ node = selection.anchorNode
node and @isDOMDescendant element, node
else
- 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.
+ # 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
@@ -191,13 +190,12 @@ DomUtils =
handlerStack.bubbleEvent "click", target: element
else
element.focus()
- # If the cursor is at the start of the element's contents, send it to the end. Motivation:
- # * the end is a more useful place to focus than the start,
- # * we've been moving the cursor to the end for quite some time now,
- # * this way preserves the last used position (except when it's at the beginning), so the user can
- # 'resume where they left off'.
- # NOTE(mrmr1993): Some elements throw an error when we try to access their selection properties, so
- # wrap this with a try.
+ # If the cursor is at the start of the element's contents, send it to the end. Motivation:
+ # * the end is a more useful place to focus than the start,
+ # * this way preserves the last used position (except when it's at the beginning), so the user can
+ # 'resume where they left off'.
+ # NOTE(mrmr1993): Some elements throw an error when we try to access their selection properties, so
+ # wrap this with a try.
try
if element.selectionStart == 0 and element.selectionEnd == 0
element.setSelectionRange element.value.length, element.value.length