aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--background_scripts/commands.coffee22
-rw-r--r--background_scripts/main.coffee18
2 files changed, 29 insertions, 11 deletions
diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee
index 33088830..c3bc457a 100644
--- a/background_scripts/commands.coffee
+++ b/background_scripts/commands.coffee
@@ -22,17 +22,21 @@ Commands =
isBackgroundCommand: options.background
passCountToFunction: options.passCountToFunction
noRepeat: options.noRepeat
+ repeatLimit: options.repeatLimit
mapKeyToCommand: (key, command) ->
unless @availableCommands[command]
console.log(command, "doesn't exist!")
return
+ commandDetails = @availableCommands[command]
+
@keyToCommandRegistry[key] =
command: command
- isBackgroundCommand: @availableCommands[command].isBackgroundCommand
- passCountToFunction: @availableCommands[command].passCountToFunction
- noRepeat: @availableCommands[command].noRepeat
+ isBackgroundCommand: commandDetails.isBackgroundCommand
+ passCountToFunction: commandDetails.passCountToFunction
+ noRepeat: commandDetails.noRepeat
+ repeatLimit: commandDetails.repeatLimit
unmapKey: (key) -> delete @keyToCommandRegistry[key]
@@ -222,7 +226,7 @@ commandDescriptions =
copyCurrentUrl: ["Copy the current URL to the clipboard", { noRepeat: true }]
"LinkHints.activateModeToCopyLinkUrl": ["Copy a link URL to the clipboard", { noRepeat: true }]
openCopiedUrlInCurrentTab: ["Open the clipboard's URL in the current tab", { background: true }]
- openCopiedUrlInNewTab: ["Open the clipboard's URL in a new tab", { background: true }]
+ openCopiedUrlInNewTab: ["Open the clipboard's URL in a new tab", { background: true, repeatLimit: 3 }]
enterInsertMode: ["Enter insert mode", { noRepeat: true }]
@@ -256,10 +260,12 @@ commandDescriptions =
previousTab: ["Go one tab left", { background: true }]
firstTab: ["Go to the first tab", { background: true }]
lastTab: ["Go to the last tab", { background: true }]
- createTab: ["Create new tab", { background: true }]
- duplicateTab: ["Duplicate current tab", { background: true }]
- removeTab: ["Close current tab", { background: true, noRepeat: true }]
- restoreTab: ["Restore closed tab", { background: true }]
+
+ createTab: ["Create new tab", { background: true, repeatLimit: 2 }]
+ duplicateTab: ["Duplicate current tab", { background: true, repeatLimit: 2 }]
+ removeTab: ["Close current tab", { background: true, repeatLimit: 3 }]
+ restoreTab: ["Restore closed tab", { background: true, repeatLimit: 3 }]
+
moveTabToNewWindow: ["Move tab to new window", { background: true }]
togglePinTab: ["Pin/unpin current tab", { background: true }]
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index b8878358..07bb1f47 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -244,9 +244,10 @@ BackgroundCommands =
previousTab: (callback) -> selectTab(callback, "previous")
firstTab: (callback) -> selectTab(callback, "first")
lastTab: (callback) -> selectTab(callback, "last")
- removeTab: ->
+ removeTab: (callback) ->
chrome.tabs.getSelected(null, (tab) ->
- chrome.tabs.remove(tab.id))
+ chrome.tabs.remove(tab.id)
+ selectionChangedHandlers.push(callback))
restoreTab: (callback) ->
# TODO: remove if-else -block when adopted into stable
if chrome.sessions
@@ -526,10 +527,21 @@ checkKeyQueue = (keysToCheck, tabId, frameId) ->
if (Commands.keyToCommandRegistry[command])
registryEntry = Commands.keyToCommandRegistry[command]
+ runCommand = true
+
if registryEntry.noRepeat
count = 1
+ else if registryEntry.repeatLimit and count > registryEntry.repeatLimit
+ runCommand = confirm """
+ You have asked Vimium to perform #{count} repeats of the command:
+ #{Commands.availableCommands[registryEntry.command].description}
+
+ Are you sure you want to continue?
+ """
- if not registryEntry.isBackgroundCommand
+ if not runCommand
+ # Do nothing, use has chosen not to execute the command
+ else if not registryEntry.isBackgroundCommand
chrome.tabs.sendMessage(tabId,
name: "executePageCommand",
command: registryEntry.command,