Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement marks.

  • Loading branch information...
commit aeb455a577c0a20684f357ff737203b5cb419cd4 1 parent 76622cd
@int3 int3 authored
View
10 background_scripts/commands.coffee
@@ -93,7 +93,7 @@ Commands =
"LinkHints.activateMode", "LinkHints.activateModeToOpenInNewTab", "LinkHints.activateModeWithQueue",
"Vomnibar.activate", "Vomnibar.activateInNewTab", "Vomnibar.activateTabSelection",
"Vomnibar.activateBookmarks", "Vomnibar.activateBookmarksInNewTab",
- "goPrevious", "goNext", "nextFrame"]
+ "goPrevious", "goNext", "nextFrame", "Marks.activateCreateMode", "Marks.activateGotoMode"]
findCommands: ["enterFindMode", "performFind", "performBackwardsFind"]
historyNavigation:
["goBack", "goForward"]
@@ -108,7 +108,7 @@ Commands =
advancedCommands: [
"scrollToLeft", "scrollToRight",
"goUp", "focusInput", "LinkHints.activateModeWithQueue",
- "goPrevious", "goNext"]
+ "goPrevious", "goNext", "Marks.activateCreateMode", "Marks.activateGotoMode"]
defaultKeyMappings =
"?": "showHelp"
@@ -174,6 +174,9 @@ defaultKeyMappings =
"gf": "nextFrame"
+ "m": "Marks.activateCreateMode"
+ "`": "Marks.activateGotoMode"
+
# This is a mapping of: commandIdentifier => [description, options].
commandDescriptions =
@@ -240,6 +243,9 @@ commandDescriptions =
nextFrame: ["Cycle forward to the next frame on the page", { background: true, passCountToFunction: true }]
+ "Marks.activateCreateMode": ["Create a new mark"]
+ "Marks.activateGotoMode": ["Go to a mark"]
+
Commands.init()
root = exports ? window
View
4 background_scripts/main.coffee
@@ -237,7 +237,7 @@ BackgroundCommands =
# wait until that's over before we can call setScrollPosition.
chrome.tabs.create({ url: tabQueueEntry.url, index: tabQueueEntry.positionIndex }, (tab) ->
tabLoadedHandlers[tab.id] = ->
- scrollPort = chrome.tabs.sendRequest(tab.id,
+ chrome.tabs.sendRequest(tab.id,
name: "setScrollPosition",
scrollX: tabQueueEntry.scrollX,
scrollY: tabQueueEntry.scrollY)
@@ -541,6 +541,8 @@ sendRequestHandlers =
saveHelpDialogSettings: saveHelpDialogSettings,
selectSpecificTab: selectSpecificTab,
refreshCompleter: refreshCompleter
+ createMark: Marks.create.bind(Marks),
+ gotoMark: Marks.goto.bind(Marks)
# Convenience function for development use.
window.runTests = -> open(chrome.extension.getURL('tests/dom_tests/dom_tests.html'))
View
34 background_scripts/marks.coffee
@@ -0,0 +1,34 @@
+root = window.Marks = {}
+
+marks = {}
+
+root.create = (req, sender) ->
+ marks[req.markName] =
+ tabId: sender.tab.id
+ scrollX: req.scrollX
+ scrollY: req.scrollY
+
+chrome.tabs.onUpdated.addListener (tabId, changeInfo, tab) ->
+ if changeInfo.url?
+ removeMarksForTab tabId
+
+chrome.tabs.onRemoved.addListener (tabId, removeInfo) ->
+ # XXX(jez): what about restored tabs?
+ removeMarksForTab tabId
+
+removeMarksForTab = (id) ->
+ for markName, mark of marks
+ if mark.tabId is id
+ delete marks[markName]
+
+root.goto = (req, sender) ->
+ mark = marks[req.markName]
+ chrome.tabs.update mark.tabId, selected: true
+ chrome.tabs.sendRequest mark.tabId,
+ name: "setScrollPosition"
+ scrollX: mark.scrollX
+ scrollY: mark.scrollY
+ chrome.tabs.sendRequest mark.tabId,
+ name: "showHUDforDuration",
+ text: "Jumped to global mark '#{req.markName}'"
+ duration: 1000
View
45 content_scripts/marks.coffee
@@ -0,0 +1,45 @@
+root = window.Marks = {}
+
+root.activateCreateMode = ->
+ handlerStack.push keydown: (e) ->
+ keyChar = KeyboardUtils.getKeyChar(event)
+ return unless keyChar isnt ""
+
+ if /[A-Z]/.test keyChar
+ chrome.extension.sendRequest {
+ 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
+
+ @remove()
+
+ false
+
+root.activateGotoMode = ->
+ handlerStack.push keydown: (e) ->
+ keyChar = KeyboardUtils.getKeyChar(event)
+ return unless keyChar isnt ""
+
+ if /[A-Z]/.test keyChar
+ chrome.extension.sendRequest
+ 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
View
3  content_scripts/vimium_frontend.coffee
@@ -108,6 +108,7 @@ initializePreDomReady = ->
requestHandlers =
hideUpgradeNotification: -> HUD.hideUpgradeNotification()
showUpgradeNotification: (request) -> HUD.showUpgradeNotification(request.version)
+ showHUDforDuration: (request) -> HUD.showForDuration request.text, request.duration
toggleHelpDialog: (request) -> toggleHelpDialog(request.dialogHtml, request.frameId)
focusFrame: (request) -> if (frameId == request.frameId) then focusThisFrame(request.highlight)
refreshCompletionKeys: refreshCompletionKeys
@@ -203,7 +204,7 @@ executePageCommand = (request) ->
setScrollPosition = (scrollX, scrollY) ->
if (scrollX > 0 || scrollY > 0)
- DomUtils.documentReady(-> window.scrollBy(scrollX, scrollY))
+ DomUtils.documentReady(-> window.scrollTo(scrollX, scrollY))
#
# Called from the backend in order to change frame focus.
View
2  manifest.json
@@ -13,6 +13,7 @@
"lib/clipboard.js",
"background_scripts/settings.js",
"background_scripts/completion.js",
+ "background_scripts/marks.js",
"background_scripts/main.js"
]
},
@@ -35,6 +36,7 @@
"content_scripts/link_hints.js",
"content_scripts/vomnibar.js",
"content_scripts/scroller.js",
+ "content_scripts/marks.js",
"content_scripts/vimium_frontend.js"
],
"css": ["vimium.css"],
Please sign in to comment.
Something went wrong with that request. Please try again.