diff options
| author | mrmr1993 | 2017-08-15 16:41:50 +0100 | 
|---|---|---|
| committer | mrmr1993 | 2017-11-18 12:35:14 +0000 | 
| commit | 5f36adb083b86324923a9a316541a84448475dc0 (patch) | |
| tree | 258c3f2faf508cb49fb2b927b48bbb4aa7991612 | |
| parent | 72d7af375fbf4ba7fd300ae4602e45a0c2652e59 (diff) | |
| download | vimium-5f36adb083b86324923a9a316541a84448475dc0.tar.bz2 | |
FF: Add copy/paste functions to the HUD
| -rw-r--r-- | content_scripts/hud.coffee | 16 | ||||
| -rw-r--r-- | pages/hud.coffee | 11 | ||||
| -rw-r--r-- | pages/hud.html | 1 | 
3 files changed, 28 insertions, 0 deletions
| diff --git a/content_scripts/hud.coffee b/content_scripts/hud.coffee index 7c983cfa..928ae5fd 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,20 @@ 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) -> +    @hudUI.postMessage {name: "copyToClipboard", data: text} + +  pasteFromClipboard: (@pasteListener) -> +    @hudUI.postMessage {name: "pasteFromClipboard"} + +  pasteResponse: ({data}) -> +    @pasteListener data +  class Tween    opacity: 0    intervalId: -1 diff --git a/pages/hud.coffee b/pages/hud.coffee index 0d2ec2f7..6c92c7a9 100644 --- a/pages/hud.coffee +++ b/pages/hud.coffee @@ -95,5 +95,16 @@ handlers =        " (No matches)"      countElement.textContent = if showMatchText then countText else "" +  copyToClipboard: (data) -> +    focusedElement = document.activeElement +    Clipboard.copy data +    focusedElement?.focus() + +  pasteFromClipboard: -> +    focusedElement = document.activeElement +    data = Clipboard.paste() +    focusedElement?.focus() +    UIComponentServer.postMessage {name: "pasteResponse", data} +  UIComponentServer.registerHandler ({data}) -> handlers[data.name ? data]? data  FindModeHistory.init() diff --git a/pages/hud.html b/pages/hud.html index 3e8cf976..7bd27171 100644 --- a/pages/hud.html +++ b/pages/hud.html @@ -7,6 +7,7 @@      <script type="text/javascript" src="../lib/settings.js"></script>      <script type="text/javascript" src="../lib/keyboard_utils.js"></script>      <script type="text/javascript" src="../lib/find_mode_history.js"></script> +    <script type="text/javascript" src="../lib/clipboard.js"></script>      <script type="text/javascript" src="ui_component_server.js"></script>      <script type="text/javascript" src="hud.js"></script>    </head> | 
