diff options
| author | Stephen Blott | 2015-06-03 11:23:29 +0100 |
|---|---|---|
| committer | Stephen Blott | 2015-06-03 11:23:29 +0100 |
| commit | c567d7d043b689d72eabbd671eab8ae8805dadc1 (patch) | |
| tree | 776cd4fec4a7b2d3f990c01bfa36d12dbf032e50 /content_scripts | |
| parent | a402606774b8fe3bb04203f873804d61944553d6 (diff) | |
| download | vimium-c567d7d043b689d72eabbd671eab8ae8805dadc1.tar.bz2 | |
Fix marks (incl. global marks)...
Fixes #1712:
- Make global marks work.
- Add mode indicator.
- Don't fail for global marks on background page if mark is not set.
- Give HUD warning for global marks if global mark is not set.
(The diff is big but, which the exception of infrastructure refactoring,
the main change is to not exit on <Shift>, thereby fixing #1712).
Diffstat (limited to 'content_scripts')
| -rw-r--r-- | content_scripts/marks.coffee | 101 |
1 files changed, 60 insertions, 41 deletions
diff --git a/content_scripts/marks.coffee b/content_scripts/marks.coffee index 316ab951..f3dfd465 100644 --- a/content_scripts/marks.coffee +++ b/content_scripts/marks.coffee @@ -1,45 +1,64 @@ -root = window.Marks = {} -root.activateCreateMode = -> - handlerStack.push keydown: (e) -> - keyChar = KeyboardUtils.getKeyChar(event) - return unless keyChar isnt "" +exit = (mode, continuation = null) -> + mode.exit() + continuation?() + false - if /[A-Z]/.test keyChar - chrome.runtime.sendMessage { - handler: 'createMark', - markName: keyChar - scrollX: window.scrollX, - scrollY: window.scrollY - }, -> HUD.showForDuration "Created global mark '#{keyChar}'", 1000 - else if /[a-z]/.test keyChar - [baseLocation, sep, hash] = window.location.href.split '#' - localStorage["vimiumMark|#{baseLocation}|#{keyChar}"] = JSON.stringify - scrollX: window.scrollX, - scrollY: window.scrollY - HUD.showForDuration "Created local mark '#{keyChar}'", 1000 +Marks = + activateCreateMode: -> + mode = new Mode + name: "create-mark" + indicator: "Create mark?" + keypress: -> false + keyup: -> false + keydown: (event) -> + keyChar = KeyboardUtils.getKeyChar(event) + if /[A-Z]/.test keyChar + exit mode, -> + chrome.runtime.sendMessage + handler: 'createMark' + markName: keyChar + scrollX: window.scrollX + scrollY: window.scrollY + , -> HUD.showForDuration "Created global mark '#{keyChar}'.", 1000 + else if /[a-z]/.test keyChar + [baseLocation, sep, hash] = window.location.href.split '#' + localStorage["vimiumMark|#{baseLocation}|#{keyChar}"] = JSON.stringify + scrollX: window.scrollX, + scrollY: window.scrollY + exit mode, -> HUD.showForDuration "Created local mark '#{keyChar}'.", 1000 + else if event.shiftKey + false + else + exit mode - @remove() + activateGotoMode: -> + mode = new Mode + name: "goto-mark" + indicator: "Go to mark?" + keypress: -> false + keyup: -> false + keydown: (event) -> + keyChar = KeyboardUtils.getKeyChar(event) + if /[A-Z]/.test keyChar + exit mode, -> + chrome.runtime.sendMessage + handler: 'gotoMark' + markName: keyChar + else if /[a-z]/.test keyChar + [baseLocation, sep, hash] = window.location.href.split '#' + markString = localStorage["vimiumMark|#{baseLocation}|#{keyChar}"] + exit mode, -> + if markString? + mark = JSON.parse markString + window.scrollTo mark.scrollX, mark.scrollY + HUD.showForDuration "Jumped to local mark '#{keyChar}'", 1000 + else + HUD.showForDuration "Local mark not set: '#{keyChar}'.", 1000 + else if event.shiftKey + false + else + exit mode - false - -root.activateGotoMode = -> - handlerStack.push keydown: (e) -> - keyChar = KeyboardUtils.getKeyChar(event) - return unless keyChar isnt "" - - if /[A-Z]/.test keyChar - chrome.runtime.sendMessage - handler: 'gotoMark' - markName: keyChar - else if /[a-z]/.test keyChar - [baseLocation, sep, hash] = window.location.href.split '#' - markString = localStorage["vimiumMark|#{baseLocation}|#{keyChar}"] - if markString? - mark = JSON.parse markString - window.scrollTo mark.scrollX, mark.scrollY - HUD.showForDuration "Jumped to local mark '#{keyChar}'", 1000 - - @remove() - - false +root = exports ? window +root.Marks = Marks |
