diff --git a/extensions/spellcheck/src/mozInlineSpellChecker.cpp b/extensions/spellcheck/src/mozInlineSpellChecker.cpp index 12baa946456a..6fd14f4af9c3 100644 --- a/extensions/spellcheck/src/mozInlineSpellChecker.cpp +++ b/extensions/spellcheck/src/mozInlineSpellChecker.cpp @@ -95,9 +95,11 @@ static const PRTime kMaxSpellCheckTimeInUsec = INLINESPELL_CHECK_TIMEOUT * PR_USEC_PER_MSEC; mozInlineSpellStatus::mozInlineSpellStatus( - mozInlineSpellChecker* aSpellChecker, const bool aForceNavigationWordCheck, + mozInlineSpellChecker* aSpellChecker, const Operation aOp, + const bool aForceNavigationWordCheck, const int32_t aNewNavigationPositionOffset) : mSpellChecker(aSpellChecker), + mOp(aOp), mForceNavigationWordCheck(aForceNavigationWordCheck), mNewNavigationPositionOffset(aNewNavigationPositionOffset) {} @@ -111,7 +113,7 @@ mozInlineSpellStatus::mozInlineSpellStatus( // static Result, nsresult> mozInlineSpellStatus::CreateForEditorChange( - mozInlineSpellChecker& aSpellChecker, EditSubAction aEditSubAction, + mozInlineSpellChecker& aSpellChecker, const EditSubAction aEditSubAction, nsINode* aAnchorNode, uint32_t aAnchorOffset, nsINode* aPreviousNode, uint32_t aPreviousOffset, nsINode* aStartNode, uint32_t aStartOffset, nsINode* aEndNode, uint32_t aEndOffset) { @@ -121,17 +123,6 @@ mozInlineSpellStatus::CreateForEditorChange( return Err(NS_ERROR_FAILURE); } - UniquePtr status{ - /* The constructor is `private`, hence the explicit allocation. */ - new mozInlineSpellStatus{&aSpellChecker, false, 0}}; - - // save the anchor point as a range so we can find the current word later - status->mAnchorRange = - status->PositionToCollapsedRange(aAnchorNode, aAnchorOffset); - if (NS_WARN_IF(!status->mAnchorRange)) { - return Err(NS_ERROR_FAILURE); - } - bool deleted = aEditSubAction == EditSubAction::eDeleteSelectedContent; if (aEditSubAction == EditSubAction::eInsertTextComingFromIME) { // IME may remove the previous node if it cancels composition when @@ -139,17 +130,26 @@ mozInlineSpellStatus::CreateForEditorChange( deleted = !aPreviousNode->IsInComposedDoc(); } + UniquePtr status{ + /* The constructor is `private`, hence the explicit allocation. */ + new mozInlineSpellStatus{ + &aSpellChecker, deleted ? eOpChangeDelete : eOpChange, false, 0}}; + + // save the anchor point as a range so we can find the current word later + status->mAnchorRange = + status->PositionToCollapsedRange(aAnchorNode, aAnchorOffset); + if (NS_WARN_IF(!status->mAnchorRange)) { + return Err(NS_ERROR_FAILURE); + } + if (deleted) { // Deletes are easy, the range is just the current anchor. We set the range // to check to be empty, FinishInitOnEvent will fill in the range to be // the current word. - status->mOp = eOpChangeDelete; status->mRange = nullptr; return status; } - status->mOp = eOpChange; - // range to check status->mRange = nsRange::Create(aPreviousNode); @@ -231,11 +231,9 @@ mozInlineSpellStatus::CreateForNavigation( UniquePtr status{ /* The constructor is `private`, hence the explicit allocation. */ - new mozInlineSpellStatus{&aSpellChecker, aForceCheck, + new mozInlineSpellStatus{&aSpellChecker, eOpNavigation, aForceCheck, aNewPositionOffset}}; - status->mOp = eOpNavigation; - // get the root node for checking TextEditor* textEditor = status->mSpellChecker->mTextEditor; if (NS_WARN_IF(!textEditor)) { @@ -279,8 +277,7 @@ UniquePtr mozInlineSpellStatus::CreateForSelection( UniquePtr status{ /* The constructor is `private`, hence the explicit allocation. */ - new mozInlineSpellStatus{&aSpellChecker, false, 0}}; - status->mOp = eOpSelection; + new mozInlineSpellStatus{&aSpellChecker, eOpSelection, false, 0}}; return status; } @@ -297,9 +294,8 @@ UniquePtr mozInlineSpellStatus::CreateForRange( UniquePtr status{ /* The constructor is `private`, hence the explicit allocation. */ - new mozInlineSpellStatus{&aSpellChecker, false, 0}}; + new mozInlineSpellStatus{&aSpellChecker, eOpChange, false, 0}}; - status->mOp = eOpChange; status->mRange = aRange; return status; } diff --git a/extensions/spellcheck/src/mozInlineSpellChecker.h b/extensions/spellcheck/src/mozInlineSpellChecker.h index b445908acd11..09035f627956 100644 --- a/extensions/spellcheck/src/mozInlineSpellChecker.h +++ b/extensions/spellcheck/src/mozInlineSpellChecker.h @@ -84,14 +84,15 @@ class mozInlineSpellStatus { private: // @param aSpellChecker must be non-nullptr. + // @param aOp see mOp. // @param aForceNavigationWordCheck see mForceNavigationWordCheck. // @param aNewNavigationPositionOffset see mNewNavigationPositionOffset. explicit mozInlineSpellStatus(mozInlineSpellChecker* aSpellChecker, - bool aForceNavigationWordCheck, + Operation aOp, bool aForceNavigationWordCheck, int32_t aNewNavigationPositionOffset); // For resuming a previously started check. - Operation mOp; + const Operation mOp; // // If we happen to know something was inserted, this is that range.