69638: Use <span> instead of <blockquote> for plaintext quotes, to fix caret motion problems. r=mcafee, sr=sfraser

This commit is contained in:
akkana%netscape.com 2001-07-13 18:45:53 +00:00
Родитель 76d666b495
Коммит 98989d30a1
6 изменённых файлов: 83 добавлений и 6 удалений

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

@ -89,6 +89,8 @@ nsPlainTextSerializer::nsPlainTextSerializer()
mCiteQuoteLevel = 0;
mStructs = PR_TRUE; // will be read from prefs later
mHeaderStrategy = 1 /*indent increasingly*/; // ditto
mQuotesPreformatted = PR_FALSE; // ditto
mSpanLevel = 0;
for (PRInt32 i = 0; i <= 6; i++) {
mHeaderCounter[i] = 0;
}
@ -178,6 +180,8 @@ nsPlainTextSerializer::Init(PRUint32 aFlags, PRUint32 aWrapColumn,
if (NS_SUCCEEDED(rv) && prefs) {
prefs->GetBoolPref(PREF_STRUCTS, &mStructs);
prefs->GetIntPref(PREF_HEADER_STRATEGY, &mHeaderStrategy);
// The quotesPreformatted pref is a temporary measure. See bug 69638.
prefs->GetBoolPref("editor.quotesPreformatted", &mQuotesPreformatted);
}
}
@ -594,6 +598,9 @@ nsPlainTextSerializer::DoOpenContainer(PRInt32 aTag)
else if (type == eHTMLTag_dd) {
mIndent += kIndentSizeDD;
}
else if (type == eHTMLTag_span) {
++mSpanLevel;
}
// Else make sure we'll separate block level tags,
// even if we're about to leave, before doing any other formatting.
@ -742,6 +749,10 @@ nsPlainTextSerializer::DoCloseContainer(PRInt32 aTag)
else if (type == eHTMLTag_dd) {
mIndent -= kIndentSizeDD;
}
else if (type == eHTMLTag_span) {
--mSpanLevel;
}
else if (IsBlockLevel(aTag)
&& type != eHTMLTag_blockquote
&& type != eHTMLTag_script
@ -1356,9 +1367,8 @@ void
nsPlainTextSerializer::Write(const nsAReadableString& aString)
{
#ifdef DEBUG_wrapping
char* foo = ToNewCString(aString);
printf("Write(%s): wrap col = %d\n", foo, mWrapColumn);
nsMemory::Free(foo);
printf("Write(%s): wrap col = %d\n",
NS_ConvertUCS2toUTF8(aString).get(), mWrapColumn);
#endif
PRInt32 bol = 0;
@ -1366,10 +1376,16 @@ nsPlainTextSerializer::Write(const nsAReadableString& aString)
PRInt32 totLen = aString.Length();
// If the string is empty, do nothing:
if (totLen <= 0) return;
// We have two major codepaths here. One that does preformatted text and one
// that does normal formatted text. The one for preformatted text calls
// Output directly while the other code path goes through AddToLine.
if ((mPreFormatted && !mWrapColumn) || IsInPre()) {
if ((mPreFormatted && !mWrapColumn) || IsInPre()
|| (!mQuotesPreformatted && mSpanLevel > 0
//&& Substring(aString, 0, 1) == NS_LITERAL_STRING(">"))) {
&& aString.First() == PRUnichar('>'))) {
// No intelligent wrapping.
// This mustn't be mixed with intelligent wrapping without clearing

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

@ -164,6 +164,11 @@ protected:
// The width of the line as it will appear on the screen (approx.)
PRUint32 mCurrentLineWidth;
// Treat quoted text as though it's preformatted -- don't wrap it.
// Having it on a pref is a temporary measure, See bug 69638.
PRInt32 mSpanLevel;
PRBool mQuotesPreformatted;
PRBool mDoFragment;
PRInt32 mEmptyLines; // Will be the number of empty lines before
// the current. 0 if we are starting a new

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

@ -237,6 +237,10 @@ nsresult nsHTMLEditor::InsertHTMLWithCharsetAndContext(const nsAReadableString &
res = CreateListOfNodesToPaste(fragmentAsNode, address_of(nodeList), rangeStartHint, rangeEndHint);
NS_ENSURE_SUCCESS(res, res);
PRUint32 cc;
nodeList->Count(&cc);
// are there any table elements in the list?
// node and offset for insertion
nsCOMPtr<nsIDOMNode> parentNode;
@ -370,6 +374,9 @@ nsresult nsHTMLEditor::InsertHTMLWithCharsetAndContext(const nsAReadableString &
nsCOMPtr<nsISupports> isupports = dont_AddRef(nodeList->ElementAt(j));
nsCOMPtr<nsIDOMNode> curNode( do_QueryInterface(isupports) );
nsString namestr;
curNode->GetNodeName(namestr);
NS_ENSURE_TRUE(curNode, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(curNode != fragmentAsNode, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(!nsTextEditUtils::IsBody(curNode), NS_ERROR_FAILURE);
@ -583,6 +590,7 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable
PRUnichar* text = nsnull;
textDataObj->ToString ( &text );
nsAutoString debugDump (text);
stuffToPaste.Assign ( text, len / 2 );
nsAutoEditBatch beginBatching(this);
rv = InsertHTMLWithContext(stuffToPaste, aContextStr, aInfoStr);
@ -1306,6 +1314,14 @@ nsHTMLEditor::InsertAsPlaintextQuotation(const nsAReadableString & aQuotedText,
nsIDOMNode **aNodeInserted)
{
nsresult rv;
// The quotesPreformatted pref is a temporary measure. See bug 69638.
// Eventually we'll pick one way or the other.
PRBool quotesInPre;
nsCOMPtr<nsIPref> prefs = do_GetService(kPrefServiceCID, &rv);
if (NS_SUCCEEDED(rv) && prefs)
rv = prefs->GetBoolPref("editor.quotesPreformatted", &quotesInPre);
nsCOMPtr<nsIDOMNode> preNode;
// get selection
nsCOMPtr<nsISelection> selection;
@ -1326,7 +1342,12 @@ nsHTMLEditor::InsertAsPlaintextQuotation(const nsAReadableString & aQuotedText,
if (!handled)
{
// Wrap the inserted quote in a <pre> so it won't be wrapped:
nsAutoString tag; tag.AssignWithConversion("pre");
nsAutoString tag;
if (quotesInPre)
tag.Assign(NS_LITERAL_STRING("pre"));
else
tag.Assign(NS_LITERAL_STRING("span"));
rv = DeleteSelectionAndCreateNode(tag, getter_AddRefs(preNode));
// If this succeeded, then set selection inside the pre
@ -1566,6 +1587,11 @@ nsresult nsHTMLEditor::CreateListOfNodesToPaste(nsIDOMNode *aFragmentAsNode,
res = docFragRange->SetEnd(endParent, endOffset);
NS_ENSURE_SUCCESS(res, res);
nsAutoString str;
docFragRange->ToString(str);
nsCOMPtr<nsIContent> root = do_QueryInterface(aFragmentAsNode);
if (root) root->List(stdout);
// now use a subtree iterator over the range to create a list of nodes
nsTrivialFunctor functor;
nsDOMSubtreeIterator iter;

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

@ -237,6 +237,10 @@ nsresult nsHTMLEditor::InsertHTMLWithCharsetAndContext(const nsAReadableString &
res = CreateListOfNodesToPaste(fragmentAsNode, address_of(nodeList), rangeStartHint, rangeEndHint);
NS_ENSURE_SUCCESS(res, res);
PRUint32 cc;
nodeList->Count(&cc);
// are there any table elements in the list?
// node and offset for insertion
nsCOMPtr<nsIDOMNode> parentNode;
@ -370,6 +374,9 @@ nsresult nsHTMLEditor::InsertHTMLWithCharsetAndContext(const nsAReadableString &
nsCOMPtr<nsISupports> isupports = dont_AddRef(nodeList->ElementAt(j));
nsCOMPtr<nsIDOMNode> curNode( do_QueryInterface(isupports) );
nsString namestr;
curNode->GetNodeName(namestr);
NS_ENSURE_TRUE(curNode, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(curNode != fragmentAsNode, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(!nsTextEditUtils::IsBody(curNode), NS_ERROR_FAILURE);
@ -583,6 +590,7 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable
PRUnichar* text = nsnull;
textDataObj->ToString ( &text );
nsAutoString debugDump (text);
stuffToPaste.Assign ( text, len / 2 );
nsAutoEditBatch beginBatching(this);
rv = InsertHTMLWithContext(stuffToPaste, aContextStr, aInfoStr);
@ -1306,6 +1314,14 @@ nsHTMLEditor::InsertAsPlaintextQuotation(const nsAReadableString & aQuotedText,
nsIDOMNode **aNodeInserted)
{
nsresult rv;
// The quotesPreformatted pref is a temporary measure. See bug 69638.
// Eventually we'll pick one way or the other.
PRBool quotesInPre;
nsCOMPtr<nsIPref> prefs = do_GetService(kPrefServiceCID, &rv);
if (NS_SUCCEEDED(rv) && prefs)
rv = prefs->GetBoolPref("editor.quotesPreformatted", &quotesInPre);
nsCOMPtr<nsIDOMNode> preNode;
// get selection
nsCOMPtr<nsISelection> selection;
@ -1326,7 +1342,12 @@ nsHTMLEditor::InsertAsPlaintextQuotation(const nsAReadableString & aQuotedText,
if (!handled)
{
// Wrap the inserted quote in a <pre> so it won't be wrapped:
nsAutoString tag; tag.AssignWithConversion("pre");
nsAutoString tag;
if (quotesInPre)
tag.Assign(NS_LITERAL_STRING("pre"));
else
tag.Assign(NS_LITERAL_STRING("span"));
rv = DeleteSelectionAndCreateNode(tag, getter_AddRefs(preNode));
// If this succeeded, then set selection inside the pre
@ -1566,6 +1587,11 @@ nsresult nsHTMLEditor::CreateListOfNodesToPaste(nsIDOMNode *aFragmentAsNode,
res = docFragRange->SetEnd(endParent, endOffset);
NS_ENSURE_SUCCESS(res, res);
nsAutoString str;
docFragRange->ToString(str);
nsCOMPtr<nsIContent> root = do_QueryInterface(aFragmentAsNode);
if (root) root->List(stdout);
// now use a subtree iterator over the range to create a list of nodes
nsTrivialFunctor functor;
nsDOMSubtreeIterator iter;

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

@ -57,3 +57,5 @@ pref("editor.image_editor", "");
pref("editor.singleLine.pasteNewlines", 1);
pref("editor.history.url_maximum", 10);
pref("editor.quotesPreformatted", false);

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

@ -57,3 +57,5 @@ pref("editor.image_editor", "");
pref("editor.singleLine.pasteNewlines", 1);
pref("editor.history.url_maximum", 10);
pref("editor.quotesPreformatted", false);