diff options
Diffstat (limited to 'content_scripts')
| -rw-r--r-- | content_scripts/hud.coffee | 29 | ||||
| -rw-r--r-- | content_scripts/link_hints.coffee | 2 | ||||
| -rw-r--r-- | content_scripts/mode_normal.coffee | 11 | ||||
| -rw-r--r-- | content_scripts/mode_visual.coffee | 2 | 
4 files changed, 41 insertions, 3 deletions
| diff --git a/content_scripts/hud.coffee b/content_scripts/hud.coffee index 7c983cfa..42a960da 100644 --- a/content_scripts/hud.coffee +++ b/content_scripts/hud.coffee @@ -9,6 +9,8 @@ HUD =    findMode: null    abandon: -> @hudUI?.hide false +  pasteListener: null # Set by @pasteFromClipboard to handle the value returned by pasteResponse +    # This HUD is styled to precisely mimick the chrome HUD on Mac. Use the "has_popup_and_link_hud.html"    # test harness to tweak these styles to match Chrome's. One limitation of our HUD display is that    # it doesn't sit on top of horizontal scrollbars like Chrome's HUD does. @@ -82,6 +84,33 @@ HUD =      @findMode.exit()      postExit?() +  # These commands manage copying and pasting from the clipboard in the HUD frame. +  # NOTE(mrmr1993): We need this to copy and paste on Firefox: +  # * an element can't be focused in the background page, so copying/pasting doesn't work +  # * we don't want to disrupt the focus in the page, in case the page is listening for focus/blur events. +  # * the HUD shouldn't be active for this frame while any of the copy/paste commands are running. +  copyToClipboard: (text) -> +    DomUtils.documentComplete => +      @init() +      @hudUI?.postMessage {name: "copyToClipboard", data: text} + +  pasteFromClipboard: (@pasteListener) -> +    DomUtils.documentComplete => +      @init() +      # Show the HUD frame, so Firefox will actually perform the paste. +      @hudUI.toggleIframeElementClasses "vimiumUIComponentHidden", "vimiumUIComponentVisible" +      @tween.fade 0, 0 +      @hudUI.postMessage {name: "pasteFromClipboard"} + +  pasteResponse: ({data}) -> +    # Hide the HUD frame again. +    @hudUI.toggleIframeElementClasses "vimiumUIComponentVisible", "vimiumUIComponentHidden" +    @unfocusIfFocused() +    @pasteListener data + +  unfocusIfFocused: -> +    document.activeElement.blur() if document.activeElement == @hudUI?.iframeElement +  class Tween    opacity: 0    intervalId: -1 diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index ca000c90..d4a95d36 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -31,7 +31,7 @@ COPY_LINK_URL =    indicator: "Copy link URL to Clipboard"    linkActivator: (link) ->      if link.href? -      chrome.runtime.sendMessage handler: "copyToClipboard", data: link.href +      HUD.copyToClipboard link.href        url = link.href        url = url[0..25] + "...." if 28 < url.length        HUD.showForDuration "Yanked #{url}", 2000 diff --git a/content_scripts/mode_normal.coffee b/content_scripts/mode_normal.coffee index 027ad22f..e91feecf 100644 --- a/content_scripts/mode_normal.coffee +++ b/content_scripts/mode_normal.coffee @@ -91,10 +91,19 @@ NormalModeCommands =    copyCurrentUrl: ->      chrome.runtime.sendMessage { handler: "getCurrentTabUrl" }, (url) -> -      chrome.runtime.sendMessage { handler: "copyToClipboard", data: url } +      HUD.copyToClipboard url        url = url[0..25] + "...." if 28 < url.length        HUD.showForDuration("Yanked #{url}", 2000) +  openCopiedUrlInNewTab: (count) -> +    HUD.pasteFromClipboard (url) -> +      for i in [0...count] by 1 +        chrome.runtime.sendMessage { handler: "openUrlInNewTab", url } + +  openCopiedUrlInCurrentTab: -> +    HUD.pasteFromClipboard (url) -> +      chrome.runtime.sendMessage { handler: "openUrlInCurrentTab", url } +    # Mode changes.    enterInsertMode: ->      # If a focusable element receives the focus, then we exit and leave the permanently-installed insert-mode diff --git a/content_scripts/mode_visual.coffee b/content_scripts/mode_visual.coffee index f99e42f9..4c6578cd 100644 --- a/content_scripts/mode_visual.coffee +++ b/content_scripts/mode_visual.coffee @@ -312,7 +312,7 @@ class VisualMode extends KeyHandlerMode    yank: (args = {}) ->      @yankedText = @selection.toString()      @exit() -    chrome.runtime.sendMessage handler: "copyToClipboard", data: @yankedText +    HUD.copyToClipboard @yankedText      message = @yankedText.replace /\s+/g, " "      message = message[...12] + "..." if 15 < @yankedText.length | 
