Adobe-Runtime-Support
Adobe-Runtime-Support copied to clipboard
TextField return wrong .htmlText value for text ending with newline
import flash.text.TextField;
var text:String = "test\n";
var tf:TextField = new TextField();
tf.text = text;
tf.htmlText = tf.htmlText;
trace(tf.text == text); // false
the expected result is true
another example:
import flash.text.TextField;
var tf:TextField = new TextField();
tf.text = "test";
var htmlText1:String = tf.htmlText;
tf.text = "test\n";
var htmlText2:String = tf.htmlText;
trace(htmlText1 == htmlText2); // true
the expected result is false the actual result is true (different text, same htmlText)
Why this is an issue?
Imagine you're building a code highlighter or something similar. You get the .htmlText, and do something with it (just styling e.g. changing some color, some font size...). Then you set back the .htmlText and you don't want any changes to happen to the text because you just want to change the style. But currently, the text was changed. (Data loss)
related issue: #2065
What is the expected behavior?
The <p></p> means <p>I'm a paragraph</p>
So:
Case 1:
text: "" (empty)
(expected) htmlText: "<p></p>" (empty paragraph)
(actual) htmlText: "" (empty) (incorrect)
Case 2:
text: "\n"
(expected) htmlText: "<p></p><p></p>" (two empty paragraph)
(actual) htmlText: "<p></p>" (incorrect)
Case 3:
text: "\nparagraph2" (paragraph 1 is empty)
(expected) htmlText: "<p></p><p>paragraph2</p>" (paragraph 1 = empty <p></p> tag)
(actual) htmlText: "<p></p><p>paragraph2</p>" (correct)
Case 4:
text: "paragraph1"
(expected) htmlText: "<p>paragraph1</p>" (non-empty paragraph)
(actual) htmlText: "<p>paragraph1</p>" (correct)
Case 5:
text: "paragraph1\n" (paragraph 2 is empty)
(expected) htmlText: "<p>paragraph1</p><p></p>" (paragraph 2 = empty <p></p> tag)
(actual) htmlText: "<p>paragraph1</p>" (incorrect)
Case 6:
text: "paragraph1\nparagraph2"
(expected) htmlText: "<p>paragraph1</p><p>paragraph2</p>"
(actual) htmlText: "<p>paragraph1</p><p>paragraph2</p>" (correct)
Case 7:
text: "paragraph1\nparagraph2\n\n" (paragraph 3 & 4 are empty)
(expected) htmlText: "<p>paragraph1</p><p>paragraph2</p><p></p><p></p>" (paragraph 3 & 4 = empty <p></p> tag)
(actual) htmlText: "<p>paragraph1</p><p>paragraph2</p><p></p>" (incorrect)
Case 8:
text: "paragraph1\n\nparagraph3" (paragraph 2 is empty)
(expected) htmlText: "<p>paragraph1</p><p></p><p>paragraph3</p>" (paragraph 2 = empty <p></p> tag)
(actual) htmlText: "<p>paragraph1</p><p></p><p>paragraph3</p>" (correct)