diff options
| author | Stephen Blott | 2015-06-03 18:39:03 +0100 |
|---|---|---|
| committer | Stephen Blott | 2015-06-03 18:39:03 +0100 |
| commit | e005d3e5b7a06a949138109b2c57555f9a5db2b9 (patch) | |
| tree | 1de15aa6981a06b32d562c9bb2e10bba3a4c8c08 /content_scripts/marks.coffee | |
| parent | 8dab334fa2fde9d4815ce0a12c0d2ab9dd44ff05 (diff) | |
| download | vimium-e005d3e5b7a06a949138109b2c57555f9a5db2b9.tar.bz2 | |
Refactor (to setPreviousPosition) to clarify Marks logic.
Diffstat (limited to 'content_scripts/marks.coffee')
| -rw-r--r-- | content_scripts/marks.coffee | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/content_scripts/marks.coffee b/content_scripts/marks.coffee index fab509a7..9c6b1458 100644 --- a/content_scripts/marks.coffee +++ b/content_scripts/marks.coffee @@ -12,6 +12,12 @@ Marks = getLocationKey: (keyChar) -> "vimiumMark|#{window.location.href.split('#')[0]}|#{keyChar}" + getMarkString: -> + JSON.stringify scrollX: window.scrollX, scrollY: window.scrollY + + setPreviousPosition: -> + @previousPosition = @getMarkString() + showMessage: (message, keyChar) -> HUD.showForDuration "#{message} \"#{keyChar}\".", 1000 @@ -34,21 +40,16 @@ Marks = scrollY: window.scrollY , => @showMessage "Created global mark", keyChar else - @exit => @markPosition keyChar - - markPosition: (keyChar = null) -> - markString = JSON.stringify scrollX: window.scrollX, scrollY: window.scrollY - if keyChar? - localStorage[@getLocationKey keyChar] = markString - @showMessage "Created local mark", keyChar - else - @previousPosition = markString + @exit => + markString = JSON.stringify scrollX: window.scrollX, scrollY: window.scrollY + localStorage[@getLocationKey keyChar] = @getMarkString() + @showMessage "Created local mark", keyChar activateGotoMode: (registryEntry) -> # We pick off the last character of the key sequence used to launch this command. Usually this is just "`". # We then use that character, so together usually the sequence "``", to jump back to the previous - # position. The "previous position" is recorded below, and is registered via @markPosition() elsewhere - # for various other jump-like commands. + # position. The "previous position" is recorded below, and is registered via @setPreviousPosition() + # elsewhere for various other jump-like commands. previousPositionKey = registryEntry.key[registryEntry.key.length-1..] @mode = new Mode name: "goto-mark" @@ -66,7 +67,7 @@ Marks = if keyChar == previousPositionKey then @previousPosition else localStorage[@getLocationKey keyChar] @exit => if markString? - @markPosition() + @setPreviousPosition() position = JSON.parse markString window.scrollTo position.scrollX, position.scrollY @showMessage "Jumped to local mark", keyChar |
