mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 902847 - Don't trim spaces before newline for contentEditable. r=hsivonen
This commit is contained in:
parent
08c7624d01
commit
55f3f41a8e
@ -892,6 +892,8 @@ function getDocumentEncoder(element) {
|
||||
.createInstance(Ci.nsIDocumentEncoder);
|
||||
let flags = Ci.nsIDocumentEncoder.SkipInvisibleContent |
|
||||
Ci.nsIDocumentEncoder.OutputRaw |
|
||||
// Bug 902847. Don't trim trailing spaces of a line.
|
||||
Ci.nsIDocumentEncoder.OutputDontRemoveLineEndingSpaces |
|
||||
Ci.nsIDocumentEncoder.OutputLFLineBreak |
|
||||
Ci.nsIDocumentEncoder.OutputNonTextContentAsPlaceholder;
|
||||
encoder.init(element.ownerDocument, "text/plain", flags);
|
||||
|
@ -222,6 +222,11 @@ interface nsIDocumentEncoder : nsISupports
|
||||
*/
|
||||
const unsigned long OutputNonTextContentAsPlaceholder = (1 << 23);
|
||||
|
||||
/**
|
||||
* Don't Strip ending spaces from a line (only for serializing to plaintext).
|
||||
*/
|
||||
const unsigned long OutputDontRemoveLineEndingSpaces = (1 << 24);
|
||||
|
||||
/**
|
||||
* Initialize with a pointer to the document and the mime type.
|
||||
* @param aDocument Document to encode.
|
||||
|
@ -1373,6 +1373,7 @@ nsPlainTextSerializer::EndLine(bool aSoftlinebreak, bool aBreakBySpace)
|
||||
* signed messages according to the OpenPGP standard (RFC 2440).
|
||||
*/
|
||||
if (!(mFlags & nsIDocumentEncoder::OutputPreformatted) &&
|
||||
!(mFlags & nsIDocumentEncoder::OutputDontRemoveLineEndingSpaces) &&
|
||||
(aSoftlinebreak ||
|
||||
!(mCurrentLine.EqualsLiteral("-- ") || mCurrentLine.EqualsLiteral("- -- ")))) {
|
||||
// Remove spaces from the end of the line.
|
||||
|
@ -661,6 +661,7 @@ MOCHITEST_FILES_C= \
|
||||
file_CSP_bug802872.sjs \
|
||||
test_bug907892.html \
|
||||
file_bug907892.html \
|
||||
test_bug902847.html \
|
||||
$(NULL)
|
||||
|
||||
# OOP tests don't work on Windows (bug 763081) or native-fennec
|
||||
|
58
content/base/test/test_bug902847.html
Normal file
58
content/base/test/test_bug902847.html
Normal file
@ -0,0 +1,58 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=902847
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 902847</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<script type="application/javascript">
|
||||
function testPaintextSerializerWithPlaceHolder() {
|
||||
|
||||
const de = SpecialPowers.Ci.nsIDocumentEncoder;
|
||||
const Cc = SpecialPowers.Cc;
|
||||
|
||||
// Create a plaintext encoder.
|
||||
var encoder = Cc["@mozilla.org/layout/documentEncoder;1?type=text/plain"]
|
||||
.createInstance(de);
|
||||
var flags = de.OutputRaw |
|
||||
de.OutputLFLineBreak |
|
||||
de.OutputDontRemoveLineEndingSpaces;
|
||||
encoder.init(document, "text/plain", flags);
|
||||
|
||||
function toPlaintext(id) {
|
||||
var element = document.getElementById(id);
|
||||
var range = document.createRange();
|
||||
range.selectNodeContents(element);
|
||||
encoder.setRange(range);
|
||||
return encoder.encodeToString().replace('\n', '\\n', 'g')
|
||||
.replace('\r', '\\r', 'g');
|
||||
}
|
||||
|
||||
// Test cases.
|
||||
is(toPlaintext("case1"), "Hello \\nboy!", "Case 1 failed.");
|
||||
is(toPlaintext("case2"), "Hello \\nboy!", "Case 2 failed.");
|
||||
is(toPlaintext("case3"), "Hello \\nboy!", "Case 3 failed.");
|
||||
is(toPlaintext("case4"), "Hello \\nboy!", "Case 4 failed.");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
addLoadEvent(testPaintextSerializerWithPlaceHolder);
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=902847">Mozilla Bug 902847</a>
|
||||
<p id="display"></p>
|
||||
<div id="content">
|
||||
<p id="case1">Hello <br>boy!</p>
|
||||
<p id="case2">Hello <br>boy!</p>
|
||||
<p id="case3">Hello <br>boy!</p>
|
||||
<p id="case4">Hello <br>boy!</p>
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user