aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2017-04-22 07:52:23 +0100
committerStephen Blott2017-04-22 07:54:53 +0100
commit205610d6613680e2bdcc35123070ba25566f342a (patch)
tree2eadb483c4bebe67d1095684ad52890f579118e3
parent681c61d37f0b937939e739d888e93c65add51463 (diff)
downloadvimium-205610d6613680e2bdcc35123070ba25566f342a.tar.bz2
Fix global marks.
This is a follow up to the move to using keydown for all events, and fixes a bug I introduced. Specifically, we were reacting to the first keydown event, which could be just the `Shift` key.
-rw-r--r--content_scripts/marks.coffee70
1 files changed, 36 insertions, 34 deletions
diff --git a/content_scripts/marks.coffee b/content_scripts/marks.coffee
index 4a2a8203..c4b32c5e 100644
--- a/content_scripts/marks.coffee
+++ b/content_scripts/marks.coffee
@@ -36,21 +36,22 @@ Marks =
exitOnEscape: true
suppressAllKeyboardEvents: true
keydown: (event) =>
- keyChar = KeyboardUtils.getKeyChar event
- @exit =>
- if @isGlobalMark event, keyChar
- # We record the current scroll position, but only if this is the top frame within the tab.
- # Otherwise, we'll fetch the scroll position of the top frame from the background page later.
- [ scrollX, scrollY ] = [ window.scrollX, window.scrollY ] if DomUtils.isTopFrame()
- chrome.runtime.sendMessage
- handler: 'createMark'
- markName: keyChar
- scrollX: scrollX
- scrollY: scrollY
- , => @showMessage "Created global mark", keyChar
- else
- localStorage[@getLocationKey keyChar] = @getMarkString()
- @showMessage "Created local mark", keyChar
+ if KeyboardUtils.isPrintable event
+ keyChar = KeyboardUtils.getKeyChar event
+ @exit =>
+ if @isGlobalMark event, keyChar
+ # We record the current scroll position, but only if this is the top frame within the tab.
+ # Otherwise, we'll fetch the scroll position of the top frame from the background page later.
+ [ scrollX, scrollY ] = [ window.scrollX, window.scrollY ] if DomUtils.isTopFrame()
+ chrome.runtime.sendMessage
+ handler: 'createMark'
+ markName: keyChar
+ scrollX: scrollX
+ scrollY: scrollY
+ , => @showMessage "Created global mark", keyChar
+ else
+ localStorage[@getLocationKey keyChar] = @getMarkString()
+ @showMessage "Created local mark", keyChar
activateGotoMode: ->
@mode = new Mode
@@ -59,26 +60,27 @@ Marks =
exitOnEscape: true
suppressAllKeyboardEvents: true
keydown: (event) =>
- @exit =>
- keyChar = KeyboardUtils.getKeyChar event
- if @isGlobalMark event, keyChar
- # This key must match @getLocationKey() in the back end.
- key = "vimiumGlobalMark|#{keyChar}"
- Settings.storage.get key, (items) ->
- if key of items
- chrome.runtime.sendMessage handler: 'gotoMark', markName: keyChar
- HUD.showForDuration "Jumped to global mark '#{keyChar}'", 1000
- else
- HUD.showForDuration "Global mark not set '#{keyChar}'", 1000
- else
- markString = @localRegisters[keyChar] ? localStorage[@getLocationKey keyChar]
- if markString?
- @setPreviousPosition()
- position = JSON.parse markString
- window.scrollTo position.scrollX, position.scrollY
- @showMessage "Jumped to local mark", keyChar
+ if KeyboardUtils.isPrintable event
+ @exit =>
+ keyChar = KeyboardUtils.getKeyChar event
+ if @isGlobalMark event, keyChar
+ # This key must match @getLocationKey() in the back end.
+ key = "vimiumGlobalMark|#{keyChar}"
+ Settings.storage.get key, (items) ->
+ if key of items
+ chrome.runtime.sendMessage handler: 'gotoMark', markName: keyChar
+ HUD.showForDuration "Jumped to global mark '#{keyChar}'", 1000
+ else
+ HUD.showForDuration "Global mark not set '#{keyChar}'", 1000
else
- @showMessage "Local mark not set", keyChar
+ markString = @localRegisters[keyChar] ? localStorage[@getLocationKey keyChar]
+ if markString?
+ @setPreviousPosition()
+ position = JSON.parse markString
+ window.scrollTo position.scrollX, position.scrollY
+ @showMessage "Jumped to local mark", keyChar
+ else
+ @showMessage "Local mark not set", keyChar
root = exports ? window
root.Marks = Marks