How to replace selected text with other text using PURE javascript in Firefox?
This I use to select:
var sel = this.getSelection();
var range = sel.getRangeAt(0);
And also this important issue:
I want to keep the original character format (of course, the new line will have the correct format)
The selection can be made by "cross-elements" (by this I mean that the selection can contain some text from one element, such as a div or table, and some text from other elements).
For example, a document:
<div>
this is a test
</div>
<div>
<b>still a test</b>
</div>
<table style="width:100%;">
<tr>
<td>
another word</td>
<td>
stackoverflow</td>
</tr>
<tr>
<td>
bump</td>
<td>
</td>
</tr>
</table>
the user selects the following text (through one choice):
his test is still anot test
So now I want to replace the text preserving the format, for example, replace each thing with a new line =
XXX XX X XXXX XXXXX X XXXX XXXX
The final document (after replacement) will be:
<div>
tXXX XX X XXXX
</div>
<div>
<b>XXXXX X XXXX</b>
</div>
<table style="width:100%;">
<tr>
<td>
XXXXher word</td>
<td>
stackoverflow</td>
</tr>
<tr>
<td>
bump</td>
<td>
</td>
</tr>
</table>