Re: Issue 116429 in chromium: Linebreaks/newlines missing from chrome.contextMenus selectionText

61 views
Skip to first unread message

chro...@googlecode.com

unread,
Jun 28, 2012, 10:35:19 AM6/28/12
to chromi...@chromium.org

Comment #4 on issue 116429 by luke.yo...@gmail.com: Linebreaks/newlines
missing from chrome.contextMenus selectionText
http://code.google.com/p/chromium/issues/detail?id=116429

I was able to get around this using what I found here
http://stackoverflow.com/questions/5669448/get-selected-texts-html-in-div

chro...@googlecode.com

unread,
Jan 20, 2013, 10:17:44 AM1/20/13
to chromi...@chromium.org

Comment #5 on issue 116429 by yaoziy...@gmail.com: Linebreaks/newlines
missing from chrome.contextMenus selectionText
http://code.google.com/p/chromium/issues/detail?id=116429

This bug is very serious. The reason why Chrome replaces all line-breaks in
selectionText with spaces is probably that it wants to put the string as
a %s parameter in a context menu item's title, e.g. "Search Google
for '%s'...".

But there are also many scenarios where preserving line-breaks in
selectionText would be desired, such as a Chrome extension that sends
selected text to Google Translate for translation, where the text could
have multiple paragraphs.

I have an extension that also happens to want multi-line selectionText:
https://chrome.google.com/webstore/detail/pie-international/jafbohhbdpejlcfpkbbpkegglokegjid .
The extension adds diacritics to English words to show pronunciation, but
also wants to provide a context menu item "Copy without Diacritics" which
strips selected text of diacritics and copies it to the clipboard.
Naturally it wants all line-breaks in selectionText to remain intact.

I think Chrome can provide two arguments: selectionText and
selectionTextPreview, where selectionText is the full selection text with
line-breaks preserved, while selectionTextPreview is a single-line, short
preview of the full selection text and can serve as %s in context menu item
titles.

There are workarounds that inject content scripts to every tab, frame and
iframe and listens to their mouseUp and keyPress events and, upon such
events, actively sends window.getSelection().toString() to the background
page, so that they can make sure when a context menu item is clicked, the
background page always knows what is selected in the currently focused
tab/frame/iframe. But this is certainly cumbersome.

chro...@googlecode.com

unread,
Jan 20, 2013, 1:37:35 PM1/20/13
to chromi...@chromium.org

Comment #6 on issue 116429 by yaoziy...@gmail.com: Linebreaks/newlines
missing from chrome.contextMenus selectionText
http://code.google.com/p/chromium/issues/detail?id=116429

Currently I designed my own workaround:

My extension injects a content script "startscript.js" to every HTML
document (whether it is in a tab, a frame or an iframe) at document_start.
startscript gives its host document a random "documentID". Upon
document.oncontextmenu, startscript sends documentID to the extension, so
the extension knows which document has a context menu opened most recently
(call it lastDocumentID). Then, when the user clicks the context menu
item "Copy without Diacritics", the extension requests the relevant tab to
return selected text for the document identified as lastDocumentID. This
request will be sent to every frame and iframe in that tab, and each
frame/iframe's startscript will see if their documentID == lastDocumentID;
if yes, send window.getSelection().toString() back to the extension.

chro...@googlecode.com

unread,
Jan 24, 2013, 10:37:51 AM1/24/13
to chromi...@chromium.org

Comment #7 on issue 116429 by froese.m...@gmail.com: Linebreaks/newlines
missing from chrome.contextMenus selectionText
http://code.google.com/p/chromium/issues/detail?id=116429

Would like to see selectionText and selectionTextPreview as well

chro...@googlecode.com

unread,
Jan 29, 2013, 6:01:10 AM1/29/13
to chromi...@chromium.org
Updates:
Cc: plud...@chromium.org

Comment #8 on issue 116429 by mk...@chromium.org: Linebreaks/newlines
missing from chrome.contextMenus selectionText
http://code.google.com/p/chromium/issues/detail?id=116429

(No comment was entered for this change.)

Reply all
Reply to author
Forward
0 new messages