From f81c6987d5696d41c3a8b98ba8c5cecc414d263b Mon Sep 17 00:00:00 2001 From: "jfrancis%netscape.com" Date: Sat, 6 Apr 2002 19:07:47 +0000 Subject: [PATCH] fixes for bugs: 90759: spaces not working in IME editting 132133: deleting last char on line can place caret incorrectly 132837: inline style and making new list items dont play nice 103867: nsSelectionState logic error r=glazman; sr=kin; a=asa; adt=jamie; i'd also like to thank my mom, and my producer, who was there for me during detox, and of course everyone inthe academy, you are all so beautiful git-svn-id: svn://10.0.0.236/trunk@118389 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/editor/libeditor/base/nsEditor.cpp | 6 ++-- mozilla/editor/libeditor/base/nsEditor.h | 2 +- .../libeditor/base/nsSelectionState.cpp | 7 +++-- .../editor/libeditor/html/nsHTMLEditor.cpp | 17 ++++++++-- .../editor/libeditor/html/nsWSRunObject.cpp | 8 ++--- .../editor/libeditor/text/nsTextEditRules.cpp | 31 +++++++++++++++++++ .../editor/libeditor/text/nsTextEditRules.h | 5 ++- 7 files changed, 62 insertions(+), 14 deletions(-) diff --git a/mozilla/editor/libeditor/base/nsEditor.cpp b/mozilla/editor/libeditor/base/nsEditor.cpp index 52ddd146361..17e73a518f9 100644 --- a/mozilla/editor/libeditor/base/nsEditor.cpp +++ b/mozilla/editor/libeditor/base/nsEditor.cpp @@ -2304,11 +2304,13 @@ NS_IMETHODIMP nsEditor::InsertTextImpl(const nsAString& aStringToInsert, NS_IMETHODIMP nsEditor::InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert, nsIDOMCharacterData *aTextNode, - PRInt32 aOffset) + PRInt32 aOffset, PRBool suppressIME) { EditTxn *txn; nsresult result; - if (mInIMEMode) + // suppressIME s used when editor must insert text, yet this text is not + // part of current ime operation. example: adjusting whitespace around an ime insertion. + if (mInIMEMode && !suppressIME) { if (!mIMETextNode) { diff --git a/mozilla/editor/libeditor/base/nsEditor.h b/mozilla/editor/libeditor/base/nsEditor.h index 9faca20ee67..5e864ceedcb 100644 --- a/mozilla/editor/libeditor/base/nsEditor.h +++ b/mozilla/editor/libeditor/base/nsEditor.h @@ -158,7 +158,7 @@ public: nsIDOMDocument *aDoc); NS_IMETHOD InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert, nsIDOMCharacterData *aTextNode, - PRInt32 aOffset); + PRInt32 aOffset, PRBool suppressIME=PR_FALSE); NS_IMETHOD DeleteSelectionImpl(EDirection aAction); NS_IMETHOD DeleteSelectionAndCreateNode(const nsAString& aTag, nsIDOMNode ** aNewNode); diff --git a/mozilla/editor/libeditor/base/nsSelectionState.cpp b/mozilla/editor/libeditor/base/nsSelectionState.cpp index b10e4bdc527..b3483235816 100644 --- a/mozilla/editor/libeditor/base/nsSelectionState.cpp +++ b/mozilla/editor/libeditor/base/nsSelectionState.cpp @@ -543,14 +543,15 @@ nsRangeUpdater::DidRemoveContainer(nsIDOMNode *aNode, nsIDOMNode *aParent, PRInt item->startNode = aParent; item->startOffset += aOffset; } + else if ((item->startNode.get() == aParent) && (item->startOffset > aOffset)) + item->startOffset += (PRInt32)aNodeOrigLen-1; + if (item->endNode.get() == aNode) { item->endNode = aParent; item->endOffset += aOffset; } - if ((item->startNode.get() == aParent) && (item->startOffset > aOffset)) - item->startOffset += (PRInt32)aNodeOrigLen-1; - if ((item->endNode.get() == aParent) && (item->endOffset > aOffset)) + else if ((item->endNode.get() == aParent) && (item->endOffset > aOffset)) item->endOffset += (PRInt32)aNodeOrigLen-1; } return NS_OK; diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp index dc7ba7ed5eb..f127eea71d3 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp @@ -1130,7 +1130,7 @@ NS_IMETHODIMP nsHTMLEditor::HandleKeyPress(nsIDOMKeyEvent* aKeyEvent) if (keyCode == nsIDOMKeyEvent::DOM_VK_TAB) character = '\t'; else aKeyEvent->GetCharCode(&character); - if (keyCode == nsIDOMKeyEvent::DOM_VK_TAB && !(mFlags&eEditorPlaintextBit)) + if (keyCode == nsIDOMKeyEvent::DOM_VK_TAB && !(mFlags&eEditorPlaintextMask)) { nsCOMPtrselection; res = GetSelection(getter_AddRefs(selection)); @@ -1168,7 +1168,7 @@ NS_IMETHODIMP nsHTMLEditor::HandleKeyPress(nsIDOMKeyEvent* aKeyEvent) || keyCode == nsIDOMKeyEvent::DOM_VK_ENTER) { nsString empty; - if (isShift && !(mFlags&eEditorPlaintextBit)) + if (isShift && !(mFlags&eEditorPlaintextMask)) { return TypedText(empty, eTypedBR); // only inserts a br node } @@ -5404,8 +5404,19 @@ nsHTMLEditor::CopyLastEditableChildStyles(nsIDOMNode * aPreviousBlock, nsIDOMNod nsIDOMNode **aOutBrNode) { *aOutBrNode = nsnull; - nsCOMPtr child = aPreviousBlock, tmp = aPreviousBlock; + nsCOMPtr child, tmp; nsresult res; + // first, clear out aNewBlock. Contract is that we want only the styles from previousBlock. + res = aNewBlock->GetFirstChild(getter_AddRefs(child)); + while (NS_SUCCEEDED(res) && child) + { + res = DeleteNode(child); + if (NS_FAILED(res)) return res; + res = aNewBlock->GetFirstChild(getter_AddRefs(child)); + } + // now find and clone the styles + child = aPreviousBlock; + tmp = aPreviousBlock; while (tmp) { child = tmp; res = GetLastEditableChild(child, address_of(tmp)); diff --git a/mozilla/editor/libeditor/html/nsWSRunObject.cpp b/mozilla/editor/libeditor/html/nsWSRunObject.cpp index ba2f63a5bc0..b461331ca53 100644 --- a/mozilla/editor/libeditor/html/nsWSRunObject.cpp +++ b/mozilla/editor/libeditor/html/nsWSRunObject.cpp @@ -1714,7 +1714,7 @@ nsWSRunObject::ConvertToNBSP(WSPoint aPoint) // first, insert an nbsp nsAutoTxnsConserveSelection dontSpazMySelection(mHTMLEditor); nsAutoString nbspStr(nbsp); - nsresult res = mHTMLEditor->InsertTextIntoTextNodeImpl(nbspStr, textNode, aPoint.mOffset); + nsresult res = mHTMLEditor->InsertTextIntoTextNodeImpl(nbspStr, textNode, aPoint.mOffset, PR_TRUE); NS_ENSURE_SUCCESS(res, res); // next, find range of ws it will replace @@ -2055,7 +2055,7 @@ nsWSRunObject::CheckTrailingNBSPOfRun(WSFragment *aRun) return NS_ERROR_NULL_POINTER; nsAutoTxnsConserveSelection dontSpazMySelection(mHTMLEditor); nsAutoString spaceStr(PRUnichar(32)); - res = mHTMLEditor->InsertTextIntoTextNodeImpl(spaceStr, textNode, thePoint.mOffset); + res = mHTMLEditor->InsertTextIntoTextNodeImpl(spaceStr, textNode, thePoint.mOffset, PR_TRUE); NS_ENSURE_SUCCESS(res, res); // finally, delete that nbsp @@ -2097,7 +2097,7 @@ nsWSRunObject::CheckTrailingNBSP(WSFragment *aRun, nsIDOMNode *aNode, PRInt32 aO return NS_ERROR_NULL_POINTER; nsAutoTxnsConserveSelection dontSpazMySelection(mHTMLEditor); nsAutoString spaceStr(PRUnichar(32)); - res = mHTMLEditor->InsertTextIntoTextNodeImpl(spaceStr, textNode, thePoint.mOffset); + res = mHTMLEditor->InsertTextIntoTextNodeImpl(spaceStr, textNode, thePoint.mOffset, PR_TRUE); NS_ENSURE_SUCCESS(res, res); // finally, delete that nbsp @@ -2139,7 +2139,7 @@ nsWSRunObject::CheckLeadingNBSP(WSFragment *aRun, nsIDOMNode *aNode, PRInt32 aOf return NS_ERROR_NULL_POINTER; nsAutoTxnsConserveSelection dontSpazMySelection(mHTMLEditor); nsAutoString spaceStr(PRUnichar(32)); - res = mHTMLEditor->InsertTextIntoTextNodeImpl(spaceStr, textNode, thePoint.mOffset); + res = mHTMLEditor->InsertTextIntoTextNodeImpl(spaceStr, textNode, thePoint.mOffset, PR_TRUE); NS_ENSURE_SUCCESS(res, res); // finally, delete that nbsp diff --git a/mozilla/editor/libeditor/text/nsTextEditRules.cpp b/mozilla/editor/libeditor/text/nsTextEditRules.cpp index 9d66d42b98c..ff3a6b5795b 100644 --- a/mozilla/editor/libeditor/text/nsTextEditRules.cpp +++ b/mozilla/editor/libeditor/text/nsTextEditRules.cpp @@ -147,6 +147,10 @@ nsTextEditRules::Init(nsPlaintextEditor *aEditor, PRUint32 aFlags) res = CreateBogusNodeIfNeeded(selection); // this method handles null selection, which should never happen anyway if (NS_FAILED(res)) return res; + // insure trailing br node + res = CreateTrailingBRIfNeeded(); + if (NS_FAILED(res)) return res; + // create a range that is the entire body contents nsCOMPtr wholeDoc = do_CreateInstance(kRangeCID); if (!wholeDoc) return NS_ERROR_NULL_POINTER; @@ -224,6 +228,10 @@ nsTextEditRules::AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection) res = CreateBogusNodeIfNeeded(selection); if (NS_FAILED(res)) return res; + // insure trailing br node + res = CreateTrailingBRIfNeeded(); + if (NS_FAILED(res)) return res; + #ifdef IBMBIDI /* After inserting text the cursor Bidi level must be set to the level of the inserted text. * This is difficult, because we cannot know what the level is until after the Bidi algorithm @@ -1188,6 +1196,29 @@ nsTextEditRules::ReplaceNewlines(nsIDOMRange *aRange) return res; } +nsresult +nsTextEditRules::CreateTrailingBRIfNeeded() +{ + // but only if we aren't a single line edit field + if (mFlags & nsIPlaintextEditor::eEditorSingleLineMask) + return NS_OK; + nsresult res = NS_OK; + nsCOMPtr lastChild, unused; + if (!mBody) return NS_ERROR_NULL_POINTER; + res = mBody->GetLastChild(getter_AddRefs(lastChild)); + // assuming CreateBogusNodeIfNeeded() has been called first + if (NS_FAILED(res)) return res; + if (!lastChild) return NS_ERROR_NULL_POINTER; + if (!nsTextEditUtils::IsBreak(lastChild)) + { + nsAutoTxnsConserveSelection dontSpazMySelection(mEditor); + PRUint32 rootLen; + res = mEditor->GetLengthOfDOMNode(mBody, rootLen); + if (NS_FAILED(res)) return res; + res = CreateMozBR(mBody, rootLen, address_of(unused)); + } + return res; +} nsresult nsTextEditRules::CreateBogusNodeIfNeeded(nsISelection *aSelection) diff --git a/mozilla/editor/libeditor/text/nsTextEditRules.h b/mozilla/editor/libeditor/text/nsTextEditRules.h index c0343dd82ec..3b7ddf0106c 100644 --- a/mozilla/editor/libeditor/text/nsTextEditRules.h +++ b/mozilla/editor/libeditor/text/nsTextEditRules.h @@ -165,7 +165,10 @@ protected: /** replaces newllines with breaks, if needed. acts on doc portion in aRange */ nsresult ReplaceNewlines(nsIDOMRange *aRange); - /** creates a bogus text node if the document has no editable content */ + /** creates a trailing break in the text doc if there is not one already */ + nsresult CreateTrailingBRIfNeeded(); + + /** creates a bogus text node if the document has no editable content */ nsresult CreateBogusNodeIfNeeded(nsISelection *aSelection); /** returns a truncated insertion string if insertion would place us