From 5f36adb083b86324923a9a316541a84448475dc0 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 15 Aug 2017 16:41:50 +0100 Subject: FF: Add copy/paste functions to the HUD --- content_scripts/hud.coffee | 16 ++++++++++++++++ pages/hud.coffee | 11 +++++++++++ pages/hud.html | 1 + 3 files changed, 28 insertions(+) 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 @@ + -- cgit v1.2.3 From 976221f84b9694a5aa544eff8f084b78ce8c78d9 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 15 Aug 2017 16:46:44 +0100 Subject: Initialize the HUD for clipboard operations if it hasn't been already --- content_scripts/hud.coffee | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/content_scripts/hud.coffee b/content_scripts/hud.coffee index 928ae5fd..d4c38447 100644 --- a/content_scripts/hud.coffee +++ b/content_scripts/hud.coffee @@ -90,10 +90,14 @@ HUD = # * 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} + DomUtils.documentComplete => + @init() + @hudUI?.postMessage {name: "copyToClipboard", data: text} pasteFromClipboard: (@pasteListener) -> - @hudUI.postMessage {name: "pasteFromClipboard"} + DomUtils.documentComplete => + @init() + @hudUI?.postMessage {name: "pasteFromClipboard"} pasteResponse: ({data}) -> @pasteListener data -- cgit v1.2.3 From 5802b33654b5a0aeb7f331c6c392a1c61962f6ec Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 15 Aug 2017 16:51:16 +0100 Subject: FF: Add clipboardWrite permission, so we can copy to clipboard --- manifest.json | 1 + 1 file changed, 1 insertion(+) diff --git a/manifest.json b/manifest.json index 353582d1..7a8d8699 100644 --- a/manifest.json +++ b/manifest.json @@ -32,6 +32,7 @@ "bookmarks", "history", "clipboardRead", + "clipboardWrite", "storage", "sessions", "notifications", -- cgit v1.2.3 From ac79e7500c06607e86d2dcfa4cb790b7ed5befe7 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 15 Aug 2017 16:51:49 +0100 Subject: FF: Use HUD.copyToClipboard for copyCurrentUrl --- content_scripts/mode_normal.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content_scripts/mode_normal.coffee b/content_scripts/mode_normal.coffee index 027ad22f..738f009e 100644 --- a/content_scripts/mode_normal.coffee +++ b/content_scripts/mode_normal.coffee @@ -91,7 +91,7 @@ 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) -- cgit v1.2.3 From fb25b26c06eae7d00c6cfe81a7f8b9068724af03 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 15 Aug 2017 17:20:15 +0100 Subject: FF: Refocus the parent window after focusing the HUD for clipboard ops --- pages/hud.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pages/hud.coffee b/pages/hud.coffee index 6c92c7a9..f894a66c 100644 --- a/pages/hud.coffee +++ b/pages/hud.coffee @@ -99,11 +99,13 @@ handlers = focusedElement = document.activeElement Clipboard.copy data focusedElement?.focus() + window.parent.focus() pasteFromClipboard: -> focusedElement = document.activeElement data = Clipboard.paste() focusedElement?.focus() + window.parent.focus() UIComponentServer.postMessage {name: "pasteResponse", data} UIComponentServer.registerHandler ({data}) -> handlers[data.name ? data]? data -- cgit v1.2.3 From 05604d8965da712b1709d0458fa1f3ca7a1d7f2f Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 15 Aug 2017 18:54:35 +0100 Subject: FF: Use HUD.copyToClipboard everywhere --- content_scripts/link_hints.coffee | 2 +- content_scripts/mode_visual.coffee | 2 +- pages/help_dialog.coffee | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 1e4670dd..f57ec6c7 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_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 diff --git a/pages/help_dialog.coffee b/pages/help_dialog.coffee index f36155e4..08180a72 100644 --- a/pages/help_dialog.coffee +++ b/pages/help_dialog.coffee @@ -83,7 +83,7 @@ HelpDialog = commandNameElement.textContent = command.command commandNameElement.title = "Click to copy \"#{command.command}\" to clipboard." commandNameElement.addEventListener "click", -> - chrome.runtime.sendMessage handler: "copyToClipboard", data: commandNameElement.textContent + HUD.copyToClipboard commandNameElement.textContent HUD.showForDuration("Yanked #{commandNameElement.textContent}.", 2000) @showAdvancedCommands(@getShowAdvancedCommands()) -- cgit v1.2.3 From 448d609489f835162274f9ccef52918641927746 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 15 Aug 2017 17:03:37 +0100 Subject: FF: Use HUD frame for openCopiedUrlIn{Current,New}Tab --- background_scripts/commands.coffee | 4 ++-- content_scripts/mode_normal.coffee | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee index 7e171d31..4d2e1606 100644 --- a/background_scripts/commands.coffee +++ b/background_scripts/commands.coffee @@ -340,8 +340,8 @@ commandDescriptions = toggleViewSource: ["View page source", { noRepeat: true }] copyCurrentUrl: ["Copy the current URL to the clipboard", { noRepeat: 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 }] + openCopiedUrlInCurrentTab: ["Open the clipboard's URL in the current tab", { noRepeat: true }] + openCopiedUrlInNewTab: ["Open the clipboard's URL in a new tab", { repeatLimit: 20 }] enterInsertMode: ["Enter insert mode", { noRepeat: true }] passNextKey: ["Pass the next key to the page"] diff --git a/content_scripts/mode_normal.coffee b/content_scripts/mode_normal.coffee index 738f009e..e91feecf 100644 --- a/content_scripts/mode_normal.coffee +++ b/content_scripts/mode_normal.coffee @@ -95,6 +95,15 @@ NormalModeCommands = 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 -- cgit v1.2.3 From 9c1e90b32e5df1d4e3e6f9af006561184d8d81e5 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 15 Aug 2017 17:55:49 +0100 Subject: FF: Add contentEditable to clipboard operation textboxes --- lib/clipboard.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/clipboard.coffee b/lib/clipboard.coffee index 1d378e76..b37caf72 100644 --- a/lib/clipboard.coffee +++ b/lib/clipboard.coffee @@ -3,6 +3,7 @@ Clipboard = textArea = document.createElement "textarea" textArea.style.position = "absolute" textArea.style.left = "-100%" + textArea.contentEditable = "true" textArea # http://groups.google.com/group/chromium-extensions/browse_thread/thread/49027e7f3b04f68/f6ab2457dee5bf55 -- cgit v1.2.3 From ec95cc2573526355c336f0f11b45ee608470a78b Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Tue, 15 Aug 2017 22:24:30 +0100 Subject: FF: Show HUD (transparently) when pasting, manage focus changes better --- content_scripts/hud.coffee | 11 ++++++++++- pages/hud.coffee | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/content_scripts/hud.coffee b/content_scripts/hud.coffee index d4c38447..42a960da 100644 --- a/content_scripts/hud.coffee +++ b/content_scripts/hud.coffee @@ -97,11 +97,20 @@ HUD = pasteFromClipboard: (@pasteListener) -> DomUtils.documentComplete => @init() - @hudUI?.postMessage {name: "pasteFromClipboard"} + # 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/pages/hud.coffee b/pages/hud.coffee index f894a66c..99aaa2ac 100644 --- a/pages/hud.coffee +++ b/pages/hud.coffee @@ -100,6 +100,7 @@ handlers = Clipboard.copy data focusedElement?.focus() window.parent.focus() + UIComponentServer.postMessage {name: "unfocusIfFocused", data} pasteFromClipboard: -> focusedElement = document.activeElement -- cgit v1.2.3 From c8a395481eeb950c8725e3d6e0fa58510cb407aa Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Fri, 24 Nov 2017 20:26:30 +0000 Subject: FF: Use a contenteditable