bug 432415 - strip trailing newlines when editor.singleline.pasteNewlines == 2 (Copy pasting a cell from an xls/ods file adds an extra space at the end). r+sr=neil, a=beltzner

This commit is contained in:
Ted Mielczarek 2008-11-19 12:12:30 -05:00
Родитель a2f7559c82
Коммит d9375b27d7
2 изменённых файлов: 17 добавлений и 8 удалений

Просмотреть файл

@ -585,6 +585,8 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
switch(mEditor->mNewlineHandling)
{
case nsIPlaintextEditor::eNewlinesReplaceWithSpaces:
// Strip trailing newlines first so we don't wind up with trailing spaces
tString.Trim(CRLF, PR_FALSE, PR_TRUE);
tString.ReplaceChar(CRLF, ' ');
break;
case nsIPlaintextEditor::eNewlinesStrip:

Просмотреть файл

@ -41,6 +41,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=253481
<![CDATA[
/** Test for Bug 253481 **/
function testPaste(name, element, expected) {
element.value = "";
element.focus();
synthesizeKey("v", { accelKey: true });
is(element.value, expected, name);
@ -50,20 +51,26 @@ SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
setTimeout(function() {
var testString = " hello hello \n world\nworld ";
var testString = "\n hello hello \n world\nworld \n";
var expectedResults = {
"pasteintact": testString,
"pastetofirst": testString.split(/\n/)[0],
"replacewithspaces": testString.replace('\n',' ','g'),
// even "pasteintact" strips leading/trailing newlines
"pasteintact": testString.replace(/^\n/, '').replace(/\n$/, ''),
// "pastetofirst" strips leading newlines
"pastetofirst": testString.replace(/^\n/, '').split(/\n/)[0],
// "replacewithspaces" strips trailing newlines first - bug 432415
"replacewithspaces": testString.replace(/\n$/, '').replace('\n',' ','g'),
// "strip" is pretty straightforward
"strip": testString.replace('\n','','g'),
"replacewithcommas": testString.replace('\n',',','g'),
// "replacewithcommas" strips leading and trailing newlines first
"replacewithcommas": testString.replace(/^\n/, '').replace(/\n$/, '').replace('\n',',','g'),
// "stripsurroundingwhitespace" strips all newlines and whitespace around them
"stripsurroundingwhitespace": testString.replace(/\s*\n\s*/g,'')
};
// Put a multi-line string in the clipboard
Components.classes["@mozilla.org/widget/clipboardhelper;1"]
.getService(Components.interfaces.nsIClipboardHelper)
.copyString(testString);
var clip = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
.getService(Components.interfaces.nsIClipboardHelper);
clip.copyString(testString);
for (let [item, expected] in Iterator(expectedResults)) {
testPaste(item, $(item), expected);