Open
Bug 1271534
Opened 9 years ago
Updated 2 years ago
Add ability to get visible text as-is from DOM Range
Categories
(WebExtensions :: General, defect, P5)
WebExtensions
General
Tracking
(Not tracked)
NEW
People
(Reporter: yuki, Unassigned)
References
Details
(Whiteboard: [design-decision-approved] triaged)
When I tried to migrate my addon "Text Link" and "XUL/Migemo" from XUL-based to WebExtensions, I've realized that it is impossible to get actual visible text as-is from DOM Range (and selection).
For example, if there is an HTML fragment and a selection:
~~~
<p style="white-space: pre-wrap">[SELECTION START]path/to/file1.jpg<br><span style="display: none">path/to/file2.jpg<br></span>path/to/file3.jpg[SELECTION END]<br>...</p>
~~~
It will be rendered like:
~~~
[SELECTION START]path/to/file1.jpg
path/to/file3.jpg[SELECTION END]
...
~~~
I hope to get actual visible text like "path/to/file1.jpg\npath/to/file3.jpg" from the selection range, but it is impossible. `window.getSelection().getRangeAt(0).toString()` returns a string "path/to/file1.jpgpath/to/file2.jpgpath/to/file3.jpg", because DOM Range's `toString()` doesn't consider actual rendering result. The actual result doesn't have any line break produced by <br> and it has unnecessary "path/to/file2.jpg" in invisible element.
In XUL-based addon it can be done by nsIDocumentEncoder, like:
~~~
var encoder = Cc['@mozilla.org/layout/documentEncoder;1?type=text/plain'].createInstance(Ci.nsIDocumentEncoder);
encoder.init(range.startContainer.ownerDocument, 'text/plain', encoder.OutputBodyOnly | encoder.OutputLFLineBreak | encoder.SkipInvisibleContent);
encoder.setRange(range);
var result = encoder.encodeToString();
~~~
After XUL is ended we need something to alter the workaround with nsIDocumentEncoder.
Reporter | ||
Updated•9 years ago
|
Blocks: webextensions-additional-apis
Updated•9 years ago
|
Whiteboard: [design-decision-needed] triaged
Comment 1•8 years ago
|
||
To be discussed at January 24 WebExtensions triage meeting.
Agenda: https://docs.google.com/document/d/1add-6FL8mzksvzbyB83HUmEkVmKERd-nt740AYr-4PE/edit#
Updated•8 years ago
|
Priority: -- → P5
Whiteboard: [design-decision-needed] triaged → [design-decision-approved] triaged
Reporter | ||
Comment 2•7 years ago
|
||
As a workaround, I've implemented this function based on DOM2 TreeWalker. It possibly don't work completely for some edge cases, but seems effective for most cases.
https://github.com/piroor/textlink/blob/52b3cb102df31c18a0649ee6ff0a2903864105cb/webextensions/content_scripts/range.js#L8
Updated•6 years ago
|
Product: Toolkit → WebExtensions
Comment 3•6 years ago
|
||
Bulk move of bugs per https://bugzilla.mozilla.org/show_bug.cgi?id=1483958
status-firefox49:
affected → ---
Component: Untriaged → General
Updated•2 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•