diff options
| -rw-r--r-- | background_scripts/commands.coffee | 79 | ||||
| -rw-r--r-- | background_scripts/main.coffee | 49 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 6 | 
3 files changed, 76 insertions, 58 deletions
| diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index 918b4ad8..4a626d36 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] @@ -252,6 +256,7 @@ defaultKeyMappings =  # This is a mapping of: commandIdentifier => [description, options]. +# If the noRepeat and repeatLimit options are both specified, then noRepeat takes precedence.  commandDescriptions =    # Navigating the current page    showHelp: ["Show help", { background: true }] @@ -259,43 +264,43 @@ commandDescriptions =    scrollUp: ["Scroll up"]    scrollLeft: ["Scroll left"]    scrollRight: ["Scroll right"] -  scrollToTop: ["Scroll to the top of the page"] -  scrollToBottom: ["Scroll to the bottom of the page"] -  scrollToLeft: ["Scroll all the way to the left"] -  scrollToRight: ["Scroll all the way to the right"] +  scrollToTop: ["Scroll to the top of the page", { noRepeat: true }] +  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"]    scrollPageUp: ["Scroll a page up"]    scrollFullPageDown: ["Scroll a full page down"]    scrollFullPageUp: ["Scroll a full page up"] -  reload: ["Reload the page"] -  toggleViewSource: ["View page source"] +  reload: ["Reload the page", { noRepeat: true }] +  toggleViewSource: ["View page source", { noRepeat: true }] -  copyCurrentUrl: ["Copy the current URL to the clipboard"] -  'LinkHints.activateModeToCopyLinkUrl': ["Copy a link URL to the clipboard"] +  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"] +  enterInsertMode: ["Enter insert mode", { noRepeat: true }]    focusInput: ["Focus the first text box on the page. Cycle between them using tab",      { 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"] - -  "LinkHints.activateModeToOpenIncognito": ["Open a link in incognito window"] +  "LinkHints.activateMode": ["Open a link in the current tab", { noRepeat: true }] +  "LinkHints.activateModeToOpenInNewTab": ["Open a link in a new tab", { noRepeat: true }] +  "LinkHints.activateModeToOpenInNewForegroundTab": ["Open a link in a new tab & switch to it", { noRepeat: true }] +  "LinkHints.activateModeWithQueue": ["Open multiple links in a new tab", { noRepeat: true }] +  "LinkHints.activateModeToOpenIncognito": ["Open a link in incognito window", { noRepeat: true }] +  "LinkHints.activateModeToDownloadLink": ["Download link url", { noRepeat: true }] -  "LinkHints.activateModeToDownloadLink": ["Download link url"] -  enterFindMode: ["Enter find mode"] +  enterFindMode: ["Enter find mode", { noRepeat: true }]    performFind: ["Cycle forward to the next find match"]    performBackwardsFind: ["Cycle backward to the previous find match"] -  goPrevious: ["Follow the link labeled previous or <"] -  goNext: ["Follow the link labeled next or >"] +  goPrevious: ["Follow the link labeled previous or <", { noRepeat: true }] +  goNext: ["Follow the link labeled next or >", { noRepeat: true }]    # Navigating your history    goBack: ["Go back in history", { passCountToFunction: true }] @@ -310,10 +315,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 }] @@ -324,18 +331,18 @@ commandDescriptions =    moveTabLeft: ["Move tab to the left", { background: true, passCountToFunction: true }]    moveTabRight: ["Move tab to the right", { background: true, passCountToFunction: true  }] -  "Vomnibar.activate": ["Open URL, bookmark, or history entry"] -  "Vomnibar.activateInNewTab": ["Open URL, bookmark, history entry, in a new tab"] -  "Vomnibar.activateTabSelection": ["Search through your open tabs"] -  "Vomnibar.activateBookmarks": ["Open a bookmark"] -  "Vomnibar.activateBookmarksInNewTab": ["Open a bookmark in a new tab"] -  "Vomnibar.activateEditUrl": ["Edit the current URL"] -  "Vomnibar.activateEditUrlInNewTab": ["Edit the current URL and open in a new tab"] +  "Vomnibar.activate": ["Open URL, bookmark, or history entry", { noRepeat: true }] +  "Vomnibar.activateInNewTab": ["Open URL, bookmark, history entry, in a new tab", { noRepeat: true }] +  "Vomnibar.activateTabSelection": ["Search through your open tabs", { noRepeat: true }] +  "Vomnibar.activateBookmarks": ["Open a bookmark", { noRepeat: true }] +  "Vomnibar.activateBookmarksInNewTab": ["Open a bookmark in a new tab", { noRepeat: true }] +  "Vomnibar.activateEditUrl": ["Edit the current URL", { noRepeat: true }] +  "Vomnibar.activateEditUrlInNewTab": ["Edit the current URL and open in a new tab", { noRepeat: true }]    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"] +  "Marks.activateCreateMode": ["Create a new mark", { noRepeat: true }] +  "Marks.activateGotoMode": ["Go to a mark", { noRepeat: true }]  Commands.init() diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 14ce7b0f..898f46f1 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 @@ -530,23 +531,35 @@ checkKeyQueue = (keysToCheck, tabId, frameId) ->    if (Commands.keyToCommandRegistry[command])      registryEntry = Commands.keyToCommandRegistry[command] - -    if !registryEntry.isBackgroundCommand -      chrome.tabs.sendMessage(tabId, -        name: "executePageCommand", -        command: registryEntry.command, -        frameId: frameId, -        count: count, -        passCountToFunction: registryEntry.passCountToFunction, -        completionKeys: generateCompletionKeys("")) -      refreshedCompletionKeys = true -    else -      if registryEntry.passCountToFunction -        BackgroundCommands[registryEntry.command](count) -      else if registryEntry.noRepeat -        BackgroundCommands[registryEntry.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 runCommand +      if not registryEntry.isBackgroundCommand +        chrome.tabs.sendMessage(tabId, +          name: "executePageCommand", +          command: registryEntry.command, +          frameId: frameId, +          count: count, +          passCountToFunction: registryEntry.passCountToFunction, +          completionKeys: generateCompletionKeys("")) +        refreshedCompletionKeys = true        else -        repeatFunction(BackgroundCommands[registryEntry.command], count, 0, frameId) +        if registryEntry.passCountToFunction +          BackgroundCommands[registryEntry.command](count) +        else if registryEntry.noRepeat +          BackgroundCommands[registryEntry.command]() +        else +          repeatFunction(BackgroundCommands[registryEntry.command], count, 0, frameId)      newKeyQueue = ""    else if (getActualKeyStrokeLength(command) > 1) diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 4f7becba..d4347f26 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -398,12 +398,10 @@ onKeydown = (event) ->          keyChar = "<" + keyChar + ">"    if (isInsertMode() && KeyboardUtils.isEscape(event)) -    # Note that we can't programmatically blur out of Flash embeds from Javascript. -    if (!isEmbed(event.srcElement)) +    if isEditable(event.srcElement) or isEmbed(event.srcElement)        # Remove focus so the user can't just get himself back into insert mode by typing in the same input        # box. -      if (isEditable(event.srcElement)) -        event.srcElement.blur() +      event.srcElement.blur()        exitInsertMode()        DomUtils.suppressEvent event        handledKeydownEvents.push event | 
