From fa37dd981f2212505e288feb2bf30d8509eb5edd Mon Sep 17 00:00:00 2001 From: "kin%netscape.com" Date: Fri, 11 May 2001 13:59:11 +0000 Subject: [PATCH] Fix for bug #75305: Doing Undo and Redo crashes browser Added nsAutoUpdateViewBatch class, and use it in nsPlaintexteditor::Undo()/Redo(). editor/base/nsEditorUtils.h editor/base/nsPlaintextEditor.cpp r=jfrancis@netscape.com sr=sfraser@netscape.com --- editor/base/nsEditorUtils.h | 25 +++++++++++++++++++++ editor/base/nsPlaintextEditor.cpp | 3 +++ editor/libeditor/base/nsEditorUtils.h | 25 +++++++++++++++++++++ editor/libeditor/text/nsPlaintextEditor.cpp | 3 +++ 4 files changed, 56 insertions(+) diff --git a/editor/base/nsEditorUtils.h b/editor/base/nsEditorUtils.h index 8fb8407a443..10b20a46273 100644 --- a/editor/base/nsEditorUtils.h +++ b/editor/base/nsEditorUtils.h @@ -144,6 +144,31 @@ class nsAutoTxnsConserveSelection PRBool mOldState; }; +/*************************************************************************** + * stack based helper class for batching reflow and paint requests. + */ +class nsAutoUpdateViewBatch +{ + public: + + nsAutoUpdateViewBatch(nsEditor *ed) : mEd(ed) + { + NS_ASSERTION(mEd, "null mEd pointer!"); + + if (mEd) + mEd->BeginUpdateViewBatch(); + } + + ~nsAutoUpdateViewBatch() + { + if (mEd) + mEd->EndUpdateViewBatch(); + } + + protected: + nsEditor *mEd; +}; + /****************************************************************************** * some helper classes for iterating the dom tree *****************************************************************************/ diff --git a/editor/base/nsPlaintextEditor.cpp b/editor/base/nsPlaintextEditor.cpp index 37b385360cc..ddc0ad8e7ee 100644 --- a/editor/base/nsPlaintextEditor.cpp +++ b/editor/base/nsPlaintextEditor.cpp @@ -1301,6 +1301,8 @@ nsPlaintextEditor::SetWrapWidth(PRInt32 aWrapColumn) NS_IMETHODIMP nsPlaintextEditor::Undo(PRUint32 aCount) { + nsAutoUpdateViewBatch beginViewBatching(this); + ForceCompositionEnd(); nsresult result = NS_OK; @@ -1327,6 +1329,7 @@ nsPlaintextEditor::Redo(PRUint32 aCount) { nsresult result = NS_OK; + nsAutoUpdateViewBatch beginViewBatching(this); nsAutoRules beginRulesSniffing(this, kOpRedo, nsIEditor::eNone); nsTextRulesInfo ruleInfo(nsTextEditRules::kRedo); diff --git a/editor/libeditor/base/nsEditorUtils.h b/editor/libeditor/base/nsEditorUtils.h index 8fb8407a443..10b20a46273 100644 --- a/editor/libeditor/base/nsEditorUtils.h +++ b/editor/libeditor/base/nsEditorUtils.h @@ -144,6 +144,31 @@ class nsAutoTxnsConserveSelection PRBool mOldState; }; +/*************************************************************************** + * stack based helper class for batching reflow and paint requests. + */ +class nsAutoUpdateViewBatch +{ + public: + + nsAutoUpdateViewBatch(nsEditor *ed) : mEd(ed) + { + NS_ASSERTION(mEd, "null mEd pointer!"); + + if (mEd) + mEd->BeginUpdateViewBatch(); + } + + ~nsAutoUpdateViewBatch() + { + if (mEd) + mEd->EndUpdateViewBatch(); + } + + protected: + nsEditor *mEd; +}; + /****************************************************************************** * some helper classes for iterating the dom tree *****************************************************************************/ diff --git a/editor/libeditor/text/nsPlaintextEditor.cpp b/editor/libeditor/text/nsPlaintextEditor.cpp index 37b385360cc..ddc0ad8e7ee 100644 --- a/editor/libeditor/text/nsPlaintextEditor.cpp +++ b/editor/libeditor/text/nsPlaintextEditor.cpp @@ -1301,6 +1301,8 @@ nsPlaintextEditor::SetWrapWidth(PRInt32 aWrapColumn) NS_IMETHODIMP nsPlaintextEditor::Undo(PRUint32 aCount) { + nsAutoUpdateViewBatch beginViewBatching(this); + ForceCompositionEnd(); nsresult result = NS_OK; @@ -1327,6 +1329,7 @@ nsPlaintextEditor::Redo(PRUint32 aCount) { nsresult result = NS_OK; + nsAutoUpdateViewBatch beginViewBatching(this); nsAutoRules beginRulesSniffing(this, kOpRedo, nsIEditor::eNone); nsTextRulesInfo ruleInfo(nsTextEditRules::kRedo);