aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2016-03-26 12:08:43 +0000
committerStephen Blott2016-03-26 12:08:43 +0000
commitbfeaeae0df589e5163cdc9e99ea9d3c3b1b15038 (patch)
treeae5f417e29a060efebaf74b12110dd315a92115a
parent24d305500b4fd3574ed31cff33b177f42cd88457 (diff)
parente133f8d2b3d104568959759e8ec7cf907257eb1b (diff)
downloadvimium-bfeaeae0df589e5163cdc9e99ea9d3c3b1b15038.tar.bz2
Merge branch 'standardise-foreground-commands'
Conflicts: content_scripts/vimium_frontend.coffee
-rw-r--r--background_scripts/commands.coffee64
-rw-r--r--content_scripts/marks.coffee2
-rw-r--r--content_scripts/vimium_frontend.coffee10
-rw-r--r--lib/utils.coffee4
4 files changed, 36 insertions, 44 deletions
diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee
index 6c452242..2d901b15 100644
--- a/background_scripts/commands.coffee
+++ b/background_scripts/commands.coffee
@@ -1,7 +1,7 @@
Commands =
init: ->
- for own command, description of commandDescriptions
- @addCommand(command, description[0], description[1])
+ for own command, descriptor of commandDescriptions
+ @addCommand(command, descriptor[0], descriptor[1])
@loadKeyMappings Settings.get "keyMappings"
Settings.postUpdateHooks["keyMappings"] = @loadKeyMappings.bind this
@@ -16,14 +16,11 @@ Commands =
# Registers a command, making it available to be optionally bound to a key.
# options:
# - background: whether this command needs to be run against the background page.
- # - passCountToFunction: true if this command should have any digits which were typed prior to the
- # command passed to it. This is used to implement e.g. "closing of 3 tabs".
- addCommand: (command, description, options) ->
+ addCommand: (command, description, options = {}) ->
if command of @availableCommands
BgUtils.log "#{command} is already defined! Check commands.coffee for duplicates."
return
- options ||= {}
@availableCommands[command] = extend options, description: description
mapKeyToCommand: ({ key, command, options }) ->
@@ -134,7 +131,6 @@ Commands =
"reload",
"toggleViewSource",
"copyCurrentUrl",
- "LinkHints.activateModeToCopyLinkUrl",
"openCopiedUrlInCurrentTab",
"openCopiedUrlInNewTab",
"goUp",
@@ -150,6 +146,7 @@ Commands =
"LinkHints.activateModeWithQueue",
"LinkHints.activateModeToDownloadLink",
"LinkHints.activateModeToOpenIncognito",
+ "LinkHints.activateModeToCopyLinkUrl",
"goPrevious",
"goNext",
"nextFrame",
@@ -241,9 +238,10 @@ defaultKeyMappings =
"gi": "focusInput"
- "f": "LinkHints.activateMode"
- "F": "LinkHints.activateModeToOpenInNewTab"
+ "f": "LinkHints.activateMode"
+ "F": "LinkHints.activateModeToOpenInNewTab"
"<a-f>": "LinkHints.activateModeWithQueue"
+ "yf": "LinkHints.activateModeToCopyLinkUrl"
"/": "enterFindMode"
"n": "performFind"
@@ -253,7 +251,6 @@ defaultKeyMappings =
"]]": "goNext"
"yy": "copyCurrentUrl"
- "yf": "LinkHints.activateModeToCopyLinkUrl"
"p": "openCopiedUrlInCurrentTab"
"P": "openCopiedUrlInNewTab"
@@ -299,43 +296,42 @@ defaultKeyMappings =
commandDescriptions =
# Navigating the current page
showHelp: ["Show help", { background: true, noRepeat: true }]
- scrollDown: ["Scroll down", { passCountToFunction: true }]
- scrollUp: ["Scroll up", { passCountToFunction: true }]
- scrollLeft: ["Scroll left", { passCountToFunction: true }]
- scrollRight: ["Scroll right", { passCountToFunction: true }]
+ scrollDown: ["Scroll down"]
+ scrollUp: ["Scroll up"]
+ scrollLeft: ["Scroll left"]
+ scrollRight: ["Scroll right"]
- scrollToTop: ["Scroll to the top of the page", { passCountToFunction: true }]
+ scrollToTop: ["Scroll to the top of the page"]
scrollToBottom: ["Scroll to the bottom of the page", { noRepeat: true }]
scrollToLeft: ["Scroll all the way to the left", { noRepeat: true }]
scrollToRight: ["Scroll all the way to the right", { noRepeat: true }]
- scrollPageDown: ["Scroll a page down", { passCountToFunction: true }]
- scrollPageUp: ["Scroll a page up", { passCountToFunction: true }]
- scrollFullPageDown: ["Scroll a full page down", { passCountToFunction: true }]
- scrollFullPageUp: ["Scroll a full page up", { passCountToFunction: true }]
+ scrollPageDown: ["Scroll a page down"]
+ scrollPageUp: ["Scroll a page up"]
+ scrollFullPageDown: ["Scroll a full page down"]
+ scrollFullPageUp: ["Scroll a full page up"]
reload: ["Reload the page", { noRepeat: true }]
toggleViewSource: ["View page source", { noRepeat: true }]
copyCurrentUrl: ["Copy the current URL to the clipboard", { noRepeat: true }]
- "LinkHints.activateModeToCopyLinkUrl": ["Copy a link URL to the clipboard", { passCountToFunction: true }]
openCopiedUrlInCurrentTab: ["Open the clipboard's URL in the current tab", { background: true, noRepeat: true }]
openCopiedUrlInNewTab: ["Open the clipboard's URL in a new tab", { background: true, repeatLimit: 20 }]
enterInsertMode: ["Enter insert mode", { noRepeat: true }]
- passNextKey: ["Pass the next key to Chrome", { passCountToFunction: true }]
+ passNextKey: ["Pass the next key to Chrome"]
enterVisualMode: ["Enter visual mode", { noRepeat: true }]
enterVisualLineMode: ["Enter visual line mode", { noRepeat: true }]
- focusInput: ["Focus the first text box on the page. Cycle between them using tab",
- { passCountToFunction: true }]
+ focusInput: ["Focus the first text box on the page. Cycle between them using tab"]
- "LinkHints.activateMode": ["Open a link in the current tab", { passCountToFunction: true }]
- "LinkHints.activateModeToOpenInNewTab": ["Open a link in a new tab", { passCountToFunction: true }]
- "LinkHints.activateModeToOpenInNewForegroundTab": ["Open a link in a new tab & switch to it", { passCountToFunction: true }]
+ "LinkHints.activateMode": ["Open a link in the current tab"]
+ "LinkHints.activateModeToOpenInNewTab": ["Open a link in a new tab"]
+ "LinkHints.activateModeToOpenInNewForegroundTab": ["Open a link in a new tab & switch to it"]
"LinkHints.activateModeWithQueue": ["Open multiple links in a new tab", { noRepeat: true }]
- "LinkHints.activateModeToOpenIncognito": ["Open a link in incognito window", { passCountToFunction: true }]
- "LinkHints.activateModeToDownloadLink": ["Download link url", { passCountToFunction: true }]
+ "LinkHints.activateModeToOpenIncognito": ["Open a link in incognito window"]
+ "LinkHints.activateModeToDownloadLink": ["Download link url"]
+ "LinkHints.activateModeToCopyLinkUrl": ["Copy a link URL to the clipboard"]
enterFindMode: ["Enter find mode", { noRepeat: true }]
performFind: ["Cycle forward to the next find match"]
@@ -345,12 +341,12 @@ commandDescriptions =
goNext: ["Follow the link labeled next or >", { noRepeat: true }]
# Navigating your history
- goBack: ["Go back in history", { passCountToFunction: true }]
- goForward: ["Go forward in history", { passCountToFunction: true }]
+ goBack: ["Go back in history"]
+ goForward: ["Go forward in history"]
# Navigating the URL hierarchy
- goUp: ["Go up the URL hierarchy", { passCountToFunction: true }]
- goToRoot: ["Go to root of current URL hierarchy", { passCountToFunction: true }]
+ goUp: ["Go up the URL hierarchy"]
+ goToRoot: ["Go to root of current URL hierarchy"]
# Manipulating tabs
nextTab: ["Go one tab right", { background: true }]
@@ -361,9 +357,7 @@ commandDescriptions =
createTab: ["Create new tab", { background: true, repeatLimit: 20 }]
duplicateTab: ["Duplicate current tab", { background: true, repeatLimit: 20 }]
- removeTab: ["Close current tab", { background: true, repeatLimit:
- # Require confirmation to remove more tabs than we can restore.
- (if chrome.session then chrome.session.MAX_SESSION_RESULTS else 25) }]
+ removeTab: ["Close current tab", { background: true, repeatLimit: chrome.session?.MAX_SESSION_RESULTS ? 25 }]
restoreTab: ["Restore closed tab", { background: true, repeatLimit: 20 }]
moveTabToNewWindow: ["Move tab to new window", { background: true }]
diff --git a/content_scripts/marks.coffee b/content_scripts/marks.coffee
index 067d05a8..ba0467b0 100644
--- a/content_scripts/marks.coffee
+++ b/content_scripts/marks.coffee
@@ -52,7 +52,7 @@ Marks =
localStorage[@getLocationKey keyChar] = @getMarkString()
@showMessage "Created local mark", keyChar
- activateGotoMode: (registryEntry) ->
+ activateGotoMode: ->
@mode = new Mode
name: "goto-mark"
indicator: "Go to mark..."
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index e4a2e8c9..79459b76 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -121,10 +121,8 @@ class NormalMode extends KeyHandlerMode
handler: "sendMessageToFrames", message: {name: "runInTopFrame", sourceFrameId: frameId, registryEntry}
else if registryEntry.background
chrome.runtime.sendMessage {handler: "runBackgroundCommand", registryEntry, count}
- else if registryEntry.passCountToFunction
- Utils.invokeCommandString registryEntry.command, [count]
else
- Utils.invokeCommandString registryEntry.command for i in [0...count]
+ Utils.invokeCommandString registryEntry.command, count
installModes = ->
# Install the permanent modes. The permanently-installed insert mode tracks focus/blur events, and
@@ -155,7 +153,7 @@ initializePreDomReady = ->
frameFocused: ->
checkEnabledAfterURLChange: checkEnabledAfterURLChange
runInTopFrame: ({sourceFrameId, registryEntry}) ->
- Utils.invokeCommandString registryEntry.command, [sourceFrameId, registryEntry] if DomUtils.isTopFrame()
+ Utils.invokeCommandString registryEntry.command, sourceFrameId, registryEntry if DomUtils.isTopFrame()
chrome.runtime.onMessage.addListener (request, sender, sendResponse) ->
# These requests are intended for the background page, but they're delivered to the options page too.
@@ -499,8 +497,8 @@ findAndFocus = (backwards) ->
else
HUD.showForDuration("No matches for '#{FindMode.query.rawQuery}'", 1000)
-performFind = -> findAndFocus false
-performBackwardsFind = -> findAndFocus true
+performFind = (count) -> findAndFocus false for [0...count] by 1
+performBackwardsFind = (count) -> findAndFocus true for [0...count] by 1
getLinkFromSelection = ->
node = window.getSelection().anchorNode
diff --git a/lib/utils.coffee b/lib/utils.coffee
index 60d29998..3b2a59a4 100644
--- a/lib/utils.coffee
+++ b/lib/utils.coffee
@@ -11,13 +11,13 @@ Utils =
# Takes a dot-notation object string and call the function
# that it points to with the correct value for 'this'.
- invokeCommandString: (str, argArray) ->
+ invokeCommandString: (str, args...) ->
components = str.split('.')
obj = window
for component in components[0...-1]
obj = obj[component]
func = obj[components.pop()]
- func.apply(obj, argArray)
+ func.apply(obj, args)
# Escape all special characters, so RegExp will parse the string 'as is'.
# Taken from http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex