Bug 1572685 - part 4: Move HTMLEditRules::mDidEmptyParentBlocksRemoved to TopLevelEditSubActionData r=m_kato

Differential Revision: https://phabricator.services.mozilla.com/D42099

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-08-20 01:50:21 +00:00
parent 8f2394e050
commit 7b09e44b5c
3 changed files with 16 additions and 7 deletions

View File

@ -626,11 +626,15 @@ class EditorBase : public nsIEditor,
// was removed.
bool mDidDeleteNonCollapsedRange;
// If we have deleted parent empty blocks, set to true.
bool mDidDeleteEmptyParentBlocks;
private:
void Clear() {
mDidDeleteSelection = false;
mDidExplicitlySetInterLine = false;
mDidDeleteNonCollapsedRange = false;
mDidDeleteEmptyParentBlocks = false;
}
TopLevelEditSubActionData() = default;

View File

@ -192,7 +192,6 @@ HTMLEditRules::HTMLEditRules()
mInitialized(false),
mListenerEnabled(false),
mReturnInEmptyLIKillsList(false),
mDidEmptyParentBlocksRemoved(false),
mRestoreContentEditableCount(false),
mJoinOffset(0) {
mIsHTMLEditRules = true;
@ -203,7 +202,6 @@ void HTMLEditRules::InitFields() {
mHTMLEditor = nullptr;
mDocChangeRange = nullptr;
mReturnInEmptyLIKillsList = true;
mDidEmptyParentBlocksRemoved = false;
mRestoreContentEditableCount = false;
mUtilRange = nullptr;
mJoinOffset = 0;
@ -497,7 +495,9 @@ nsresult HTMLEditRules::AfterEditInner() {
HTMLEditorRef()
.TopLevelEditSubActionDataRef()
.mDidDeleteNonCollapsedRange &&
!mDidEmptyParentBlocksRemoved) {
!HTMLEditorRef()
.TopLevelEditSubActionDataRef()
.mDidDeleteEmptyParentBlocks) {
nsresult rv = InsertBRIfNeeded();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
@ -608,7 +608,9 @@ nsresult HTMLEditRules::AfterEditInner() {
// we haven't removed new empty blocks. Note that if empty block parents
// are removed, Selection should've been adjusted by the method which
// did it.
if (!mDidEmptyParentBlocksRemoved) {
if (!HTMLEditorRef()
.TopLevelEditSubActionDataRef()
.mDidDeleteEmptyParentBlocks) {
switch (HTMLEditorRef().GetTopLevelEditSubAction()) {
case EditSubAction::eInsertText:
case EditSubAction::eInsertTextComingFromIME:
@ -3172,11 +3174,15 @@ nsresult HTMLEditRules::WillDeleteSelection(
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mDidEmptyParentBlocksRemoved = rv == NS_OK;
HTMLEditorRef()
.TopLevelEditSubActionDataRef()
.mDidDeleteEmptyParentBlocks = rv == NS_OK;
}
// If we removed parent blocks, Selection should be collapsed at where
// the most ancestor empty block has been.
if (mDidEmptyParentBlocksRemoved) {
if (HTMLEditorRef()
.TopLevelEditSubActionDataRef()
.mDidDeleteEmptyParentBlocks) {
rv = SelectionRefPtr()->Collapse(startNode, startOffset);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;

View File

@ -1351,7 +1351,6 @@ class HTMLEditRules : public TextEditRules {
bool mInitialized;
bool mListenerEnabled;
bool mReturnInEmptyLIKillsList;
bool mDidEmptyParentBlocksRemoved;
bool mRestoreContentEditableCount;
RefPtr<nsRange> mUtilRange;
// Need to remember an int across willJoin/didJoin...