diff options
| author | Stephen Blott | 2015-02-04 14:18:11 +0000 |
|---|---|---|
| committer | Stephen Blott | 2015-02-04 14:18:11 +0000 |
| commit | 49a0f357e4c8b110993200a4340d9c36e9749333 (patch) | |
| tree | 35bb7b4dbe18abbb79a7a0b2e3ea3125891fb7a7 /content_scripts | |
| parent | f81080f951a02524b7c681546e309ede3955fbe6 (diff) | |
| download | vimium-49a0f357e4c8b110993200a4340d9c36e9749333.tar.bz2 | |
Revert "Visual/edit modes: better (?) guessing for caret mode."
This reverts commit c1681fea2f2629c6bee1e27c5dfc704d77553d96.
Diffstat (limited to 'content_scripts')
| -rw-r--r-- | content_scripts/mode_visual_edit.coffee | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/content_scripts/mode_visual_edit.coffee b/content_scripts/mode_visual_edit.coffee index 4ab425a3..8f4459ee 100644 --- a/content_scripts/mode_visual_edit.coffee +++ b/content_scripts/mode_visual_edit.coffee @@ -619,32 +619,25 @@ class CaretMode extends Movement @selection.modify "extend", forward, character # When visual mode starts and there's no existing selection, we launch CaretMode and try to establish a - # selection. As a heuristic, we score visible text nodes by their visible area and the number of - # non-whitespace characters they contain. We pick the first non-whitespece character in the highest scoring - # node. + # selection. As a heuristic, we pick the first non-whitespace character of the first visible text node + # which seems to be big enough to be interesting. + # TODO(smblott). It might be better to do something similar to Clearly or Readability; that is, try to find + # the start of the page's main textual content. establishInitialSelectionAnchor: -> nodes = document.createTreeWalker document.body, NodeFilter.SHOW_TEXT - - # Find and score candidate text nodes. - candidates = - for node in (n while n = nodes.nextNode()) - continue unless node.nodeType == 3 and 0 < node.data.trim().length + while node = nodes.nextNode() + # Don't choose short text nodes; they're likely to be part of a banner. + if node.nodeType == 3 and 50 <= node.data.trim().length element = node.parentElement - rect = DomUtils.getVisibleClientRect element - continue unless rect and not DomUtils.isEditable element - area = (rect.bottom - rect.top) * (rect.right - rect.left) - chars = node.data.split(/\s+/).join().length - { node: node, score: chars * area } - - if 0 < candidates.length - node = (candidates.sort (a,b) -> b.score - a.score)[0].node - # Start at the offset of the first non-whitespace character. - offset = node.data.length - node.data.replace(/^\s+/, "").length - range = document.createRange() - range.setStart node, offset - range.setEnd node, offset - @setSelectionRange range - return range + if DomUtils.getVisibleClientRect(element) and not DomUtils.isEditable element + # Start at the offset of the first non-whitespace character. + offset = node.data.length - node.data.replace(/^\s+/, "").length + range = document.createRange() + range.setStart node, offset + range.setEnd node, offset + @setSelectionRange range + return true + false class EditMode extends Movement constructor: (options = {}) -> |
