summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/InsertTextTransaction.cpp
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-02-07 21:36:37 +0100
committerwolfbeast <mcwerewolf@gmail.com>2018-02-07 21:36:37 +0100
commitd773eca3316f2c99db9a1dd77929bcbd157eeacb (patch)
treebe0efc8413575e2db60480a9ba5991261929b144 /editor/libeditor/InsertTextTransaction.cpp
parent1e55a5d9188b87da8632e217b238838effb1cdeb (diff)
downloadUXP-d773eca3316f2c99db9a1dd77929bcbd157eeacb.tar
UXP-d773eca3316f2c99db9a1dd77929bcbd157eeacb.tar.gz
UXP-d773eca3316f2c99db9a1dd77929bcbd157eeacb.tar.lz
UXP-d773eca3316f2c99db9a1dd77929bcbd157eeacb.tar.xz
UXP-d773eca3316f2c99db9a1dd77929bcbd157eeacb.zip
Edit transactions should store their editor instance with strong reference
Edit transactions should store their editor instance with a strong reference, and they should be released when the editor is destroyed.
Diffstat (limited to 'editor/libeditor/InsertTextTransaction.cpp')
-rw-r--r--editor/libeditor/InsertTextTransaction.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/editor/libeditor/InsertTextTransaction.cpp b/editor/libeditor/InsertTextTransaction.cpp
index 009b2d023..0434b2dd5 100644
--- a/editor/libeditor/InsertTextTransaction.cpp
+++ b/editor/libeditor/InsertTextTransaction.cpp
@@ -26,7 +26,7 @@ InsertTextTransaction::InsertTextTransaction(Text& aTextNode,
: mTextNode(&aTextNode)
, mOffset(aOffset)
, mStringToInsert(aStringToInsert)
- , mEditorBase(aEditorBase)
+ , mEditorBase(&aEditorBase)
, mRangeUpdater(aRangeUpdater)
{
}
@@ -36,6 +36,7 @@ InsertTextTransaction::~InsertTextTransaction()
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(InsertTextTransaction, EditTransactionBase,
+ mEditorBase,
mTextNode)
NS_IMPL_ADDREF_INHERITED(InsertTextTransaction, EditTransactionBase)
@@ -50,12 +51,16 @@ NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase)
NS_IMETHODIMP
InsertTextTransaction::DoTransaction()
{
+ if (NS_WARN_IF(!mEditorBase) || NS_WARN_IF(!mTextNode)) {
+ return NS_ERROR_NOT_AVAILABLE;
+ }
+
nsresult rv = mTextNode->InsertData(mOffset, mStringToInsert);
NS_ENSURE_SUCCESS(rv, rv);
// Only set selection to insertion point if editor gives permission
- if (mEditorBase.GetShouldTxnSetSelection()) {
- RefPtr<Selection> selection = mEditorBase.GetSelection();
+ if (mEditorBase->GetShouldTxnSetSelection()) {
+ RefPtr<Selection> selection = mEditorBase->GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
DebugOnly<nsresult> rv =
selection->Collapse(mTextNode, mOffset + mStringToInsert.Length());