Skip to content

Commit

Permalink
Bug 1883562 - part 2: Make EditorBase::DeleteRangesWithTransaction
Browse files Browse the repository at this point in the history
…and the fallback path of `AutoDeleteRangesHandler` work with single range r=m_kato

Although from the maintenance cost point of view, we should not duplicate
`EditorBase::DeleteRangesWithTransaction`, but let's add a wrapper for it
for making the callers simpler.

Differential Revision: https://phabricator.services.mozilla.com/D203854
masayuki-nakano committed Mar 11, 2024
1 parent 4099ab7 commit 900d40d
Showing 3 changed files with 235 additions and 146 deletions.
23 changes: 23 additions & 0 deletions editor/libeditor/EditorBase.cpp
Original file line number Diff line number Diff line change
@@ -4869,6 +4869,29 @@ nsresult EditorBase::DeleteSelectionWithTransaction(
return NS_OK;
}

Result<CaretPoint, nsresult> EditorBase::DeleteRangeWithTransaction(
nsIEditor::EDirection aDirectionAndAmount,
nsIEditor::EStripWrappers aStripWrappers, nsRange& aRangeToDelete) {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(!Destroyed());
MOZ_ASSERT(aStripWrappers == eStrip || aStripWrappers == eNoStrip);

HowToHandleCollapsedRange howToHandleCollapsedRange =
EditorBase::HowToHandleCollapsedRangeFor(aDirectionAndAmount);
if (MOZ_UNLIKELY(aRangeToDelete.Collapsed() &&
howToHandleCollapsedRange ==
HowToHandleCollapsedRange::Ignore)) {
return CaretPoint(EditorDOMPoint(aRangeToDelete.StartRef()));
}

AutoRangeArray rangesToDelete(aRangeToDelete);
Result<CaretPoint, nsresult> result = DeleteRangesWithTransaction(
aDirectionAndAmount, aStripWrappers, rangesToDelete);
NS_WARNING_ASSERTION(result.isOk(),
"EditorBase::DeleteRangesWithTransaction() failed");
return result;
}

Result<CaretPoint, nsresult> EditorBase::DeleteRangesWithTransaction(
nsIEditor::EDirection aDirectionAndAmount,
nsIEditor::EStripWrappers aStripWrappers,
19 changes: 19 additions & 0 deletions editor/libeditor/EditorBase.h
Original file line number Diff line number Diff line change
@@ -2518,6 +2518,25 @@ class EditorBase : public nsIEditor,
DeleteSelectionWithTransaction(nsIEditor::EDirection aDirectionAndAmount,
nsIEditor::EStripWrappers aStripWrappers);

/**
* DeleteRangeWithTransaction() removes content in aRangeToDelete or content
* around collapsed aRangeToDelete with transactions and remove empty
* inclusive ancestor inline elements of the collapsed range after removing
* the contents.
*
* @param aDirectionAndAmount How much range should be removed.
* @param aStripWrappers Whether the parent blocks should be removed
* when they become empty.
* Note that this must be `nsIEditor::eNoStrip`
* if this is a TextEditor because anyway it'll
* be ignored.
* @param aRangeToDelete The range to delete content.
*/
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<CaretPoint, nsresult>
DeleteRangeWithTransaction(nsIEditor::EDirection aDirectionAndAmount,
nsIEditor::EStripWrappers aStripWrappers,
nsRange& aRangeToDelete);

/**
* DeleteRangesWithTransaction() removes content in aRangesToDelete or content
* around collapsed ranges in aRangesToDelete with transactions and remove
Loading

0 comments on commit 900d40d

Please sign in to comment.