aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts
diff options
context:
space:
mode:
Diffstat (limited to 'background_scripts')
-rw-r--r--background_scripts/commands.coffee10
-rw-r--r--background_scripts/main.coffee4
-rw-r--r--background_scripts/marks.coffee34
3 files changed, 45 insertions, 3 deletions
diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee
index 69c37ac4..d7c332f9 100644
--- a/background_scripts/commands.coffee
+++ b/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
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index 20eb88d4..90220145 100644
--- a/background_scripts/main.coffee
+++ b/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'))
diff --git a/background_scripts/marks.coffee b/background_scripts/marks.coffee
new file mode 100644
index 00000000..5b38a381
--- /dev/null
+++ b/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