aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/mode_visual_edit.coffee
diff options
context:
space:
mode:
authorStephen Blott2015-01-27 04:24:34 +0000
committerStephen Blott2015-01-27 04:29:49 +0000
commit8d33db411b556b37a8b0d54aba507440cfc51e0a (patch)
tree692b1ccaec2960e994d9a6017e47c55b8548e26d /content_scripts/mode_visual_edit.coffee
parent190013f3c3b4e4c4adbd87b892589a4617141820 (diff)
downloadvimium-8d33db411b556b37a8b0d54aba507440cfc51e0a.tar.bz2
Visual/edit modes: minor changes.
Diffstat (limited to 'content_scripts/mode_visual_edit.coffee')
-rw-r--r--content_scripts/mode_visual_edit.coffee20
1 files changed, 11 insertions, 9 deletions
diff --git a/content_scripts/mode_visual_edit.coffee b/content_scripts/mode_visual_edit.coffee
index 6fadd5c8..73f154bb 100644
--- a/content_scripts/mode_visual_edit.coffee
+++ b/content_scripts/mode_visual_edit.coffee
@@ -2,10 +2,10 @@
# Todo:
# Fix word movement, particularly for "a word".
# Konami code?
-# p/P.
+# Use find as a mode.
# This prevents printable characters from being passed through to underlying page. It should, however, allow
-# through chrome keyboard shortcuts. It's a backstop for all of the modes following.
+# through chrome keyboard shortcuts. It's a keyboard-event backstop for all of the following modes.
class SuppressPrintable extends Mode
constructor: (options) ->
handler = (event) =>
@@ -18,7 +18,7 @@ class SuppressPrintable extends Mode
DomUtils.suppressPropagation
@stopBubblingAndFalse
else
- false
+ @suppressEvent
else
@stopBubblingAndTrue
@@ -65,13 +65,10 @@ class Movement extends MaintainCount
opposite: { forward: backward, backward: forward }
copy: (text) ->
- chrome.runtime.sendMessage
- handler: "copyToClipboard"
- data: text
+ chrome.runtime.sendMessage handler: "copyToClipboard", data: text if text
paste: (callback) ->
- chrome.runtime.sendMessage handler: "pasteFromClipboard", (response) ->
- callback response
+ chrome.runtime.sendMessage handler: "pasteFromClipboard", (response) -> callback response
# Swap the anchor node/offset and the focus node/offset.
reverseSelection: ->
@@ -375,21 +372,26 @@ class VisualMode extends Movement
@protectClipboard =>
initialRange = @selection.getRangeAt(0).cloneRange()
direction = @getDirection()
- which = if direction == forward then "start" else "end"
+ # Start by re-selecting the previous match, if any. This tells Chrome where to start from.
if previousFindRange
@selection.removeAllRanges()
@selection.addRange previousFindRange
window.find query, caseSensitive, findBackwards, true, false, true, false
previousFindRange = newFindRange = @selection.getRangeAt(0).cloneRange()
+ # FIXME(smblott). What if there were no matches?
+ # Now, install a range from the original selection to the new match.
range = document.createRange()
+ which = if direction == forward then "start" else "end"
range.setStart initialRange["#{which}Container"], initialRange["#{which}Offset"]
range.setEnd newFindRange.endContainer, newFindRange.endOffset
@selection.removeAllRanges()
@selection.addRange range
+ # If we're going backwards (or if the election ended up empty), then extend the selection again,
+ # this time to include the match itself.
if @getDirection() == backward or @selection.toString().length == 0
range.setStart newFindRange.startContainer, newFindRange.startOffset
@selection.removeAllRanges()