diff --git a/editor/libeditor/HTMLEditSubActionHandler.cpp b/editor/libeditor/HTMLEditSubActionHandler.cpp index 0afcb21890d8d..0925406d2d4c5 100644 --- a/editor/libeditor/HTMLEditSubActionHandler.cpp +++ b/editor/libeditor/HTMLEditSubActionHandler.cpp @@ -12736,21 +12736,44 @@ NS_ERROR_FAILURE ) ; } -EditActionResult -result -= -HandleDeleteCollapsedSelectionAtCurrentBlockBoundary +AutoBlockElementsJoiner +joiner +; +if ( -aDirectionAndAmount -MOZ_KnownLive +! +joiner +. +PrepareToDeleteCollapsedSelectionAtCurrentBlockBoundary ( * +this +aDirectionAndAmount +* scanFromStartPointResult . ElementPtr ( ) +startPoint +) +) +{ +return +EditActionCanceled +( ) +; +} +EditActionResult +result += +joiner +. +Run +( +* +this startPoint ) ; @@ -12765,12 +12788,20 @@ Succeeded HTMLEditor : : -HandleDeleteCollapsedSelectionAtCurrentBlockBoundary +AutoBlockElementsJoiner +: +: +Run ( ) +failed " " -failed +( +current +block +boundary +) " ) ; @@ -15547,12 +15578,19 @@ return result ; } -EditActionResult +bool HTMLEditor : : -HandleDeleteCollapsedSelectionAtCurrentBlockBoundary +AutoBlockElementsJoiner +: +: +PrepareToDeleteCollapsedSelectionAtCurrentBlockBoundary ( +const +HTMLEditor +& +aHTMLEditor nsIEditor : : @@ -15569,11 +15607,20 @@ aCaretPoint { MOZ_ASSERT ( +aHTMLEditor +. IsEditActionDataAvailable ( ) ) ; +mMode += +Mode +: +: +JoinCurrentBlock +; if ( HTMLEditUtils @@ -15587,18 +15634,9 @@ aCurrentBlockElement ) { return -EditActionCanceled -( -) +false ; } -nsCOMPtr -< -nsINode -> -leftNode -rightNode -; if ( aDirectionAndAmount @@ -15610,36 +15648,40 @@ nsIEditor ePrevious ) { -leftNode +mLeftContent = +aHTMLEditor +. GetPreviousEditableHTMLNode ( aCurrentBlockElement ) ; -rightNode +mRightContent = aCaretPoint . -GetContainer +GetContainerAsContent ( ) ; } else { -rightNode +mRightContent = +aHTMLEditor +. GetNextEditableHTMLNode ( aCurrentBlockElement ) ; -leftNode +mLeftContent = aCaretPoint . -GetContainer +GetContainerAsContent ( ) ; @@ -15647,39 +15689,59 @@ GetContainer if ( ! -leftNode +mLeftContent | | ! -rightNode +mRightContent ) { return -EditActionCanceled -( -) +false ; } -if -( +return +! HTMLEditor : : NodesInDifferentTableElements ( * -leftNode +mLeftContent * -rightNode +mRightContent ) +; +} +EditActionResult +HTMLEditor +: +: +AutoBlockElementsJoiner +: +: +HandleDeleteCollapsedSelectionAtCurrentBlockBoundary +( +HTMLEditor +& +aHTMLEditor +const +EditorDOMPoint +& +aCaretPoint ) { -return -EditActionCanceled +MOZ_ASSERT ( +mLeftContent +) +; +MOZ_ASSERT +( +mRightContent ) ; -} EditActionResult result ( @@ -15696,6 +15758,8 @@ aCaretPoint AutoTrackDOMPoint tracker ( +aHTMLEditor +. RangeUpdaterRef ( ) @@ -15703,63 +15767,22 @@ RangeUpdaterRef pointToPutCaret ) ; -if -( -NS_WARN_IF -( -! -leftNode -- -> -IsContent -( -) -) -| -| -NS_WARN_IF -( -! -rightNode -- -> -IsContent -( -) -) -) -{ -return -EditActionResult -( -NS_ERROR_FAILURE -) -; -} result | = +aHTMLEditor +. TryToJoinBlocksWithTransaction ( MOZ_KnownLive ( * -leftNode -- -> -AsContent -( -) +mLeftContent ) MOZ_KnownLive ( * -rightNode -- -> -AsContent -( -) +mRightContent ) ) ; @@ -15799,6 +15822,8 @@ result nsresult rv = +aHTMLEditor +. CollapseSelectionTo ( pointToPutCaret diff --git a/editor/libeditor/HTMLEditor.h b/editor/libeditor/HTMLEditor.h index 390523503a386..8aa15f219aa38 100644 --- a/editor/libeditor/HTMLEditor.h +++ b/editor/libeditor/HTMLEditor.h @@ -5474,6 +5474,34 @@ WSRunScanner aWSRunScannerAtCaret ) ; +class +MOZ_STACK_CLASS +AutoBlockElementsJoiner +final +{ +public +: +bool +PrepareToDeleteCollapsedSelectionAtCurrentBlockBoundary +( +const +HTMLEditor +& +aHTMLEditor +nsIEditor +: +: +EDirection +aDirectionAndAmount +Element +& +aCurrentBlockElement +const +EditorDOMPoint +& +aCaretPoint +) +; [ [ nodiscard @@ -5481,30 +5509,131 @@ nodiscard ] MOZ_CAN_RUN_SCRIPT EditActionResult -HandleDeleteCollapsedSelectionAtOtherBlockBoundary +Run ( -nsIEditor +HTMLEditor +& +aHTMLEditor +const +EditorDOMPoint +& +aCaretPoint +) +{ +switch +( +mMode +) +{ +case +Mode : : -EDirection -aDirectionAndAmount -nsIEditor +JoinCurrentBlock +: +{ +EditActionResult +result += +HandleDeleteCollapsedSelectionAtCurrentBlockBoundary +( +aHTMLEditor +aCaretPoint +) +; +NS_WARNING_ASSERTION +( +result +. +Succeeded +( +) +" +AutoBlockElementsJoiner : : -EStripWrappers -aStripWrappers -Element +" +" +HandleDeleteCollapsedSelectionAtCurrentBlockBoundary +( +) +failed +" +) +; +return +result +; +} +case +Mode +: +: +NotInitialized +: +return +EditActionIgnored +( +) +; +} +return +EditActionResult +( +NS_ERROR_NOT_INITIALIZED +) +; +} +private +: +[ +[ +nodiscard +] +] +MOZ_CAN_RUN_SCRIPT +EditActionResult +HandleDeleteCollapsedSelectionAtCurrentBlockBoundary +( +HTMLEditor & -aOtherBlockElement +aHTMLEditor const EditorDOMPoint & aCaretPoint -WSRunScanner -& -aWSRunScannerAtCaret ) ; +enum +class +Mode +{ +NotInitialized +JoinCurrentBlock +} +; +nsCOMPtr +< +nsIContent +> +mLeftContent +; +nsCOMPtr +< +nsIContent +> +mRightContent +; +Mode +mMode += +Mode +: +: +NotInitialized +; +} +; [ [ nodiscard @@ -5512,20 +5641,28 @@ nodiscard ] MOZ_CAN_RUN_SCRIPT EditActionResult -HandleDeleteCollapsedSelectionAtCurrentBlockBoundary +HandleDeleteCollapsedSelectionAtOtherBlockBoundary ( nsIEditor : : EDirection aDirectionAndAmount +nsIEditor +: +: +EStripWrappers +aStripWrappers Element & -aCurrentBlockElement +aOtherBlockElement const EditorDOMPoint & aCaretPoint +WSRunScanner +& +aWSRunScannerAtCaret ) ; [