Title: [293766] trunk/Source
Revision
293766
Author
megan_gard...@apple.com
Date
2022-05-04 01:33:48 -0700 (Wed, 04 May 2022)

Log Message

Enable TextCheckingType::Correction on MacCatalyst.
https://bugs.webkit.org/show_bug.cgi?id=240036

Reviewed by Wenson Hsieh.

Add TextCheckingType::Correction to Catalyst to bring consistency to macOS.

Source/WebCore:

* editing/Editor.cpp:
(WebCore::Editor::markMisspellingsAfterTypingToWord):
(WebCore::Editor::markAndReplaceFor):
(WebCore::Editor::resolveTextCheckingTypeMask):

Source/WebKit:

* UIProcess/ios/TextCheckerIOS.mm:
(WebKit::TextChecker::checkTextOfParagraph):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (293765 => 293766)


--- trunk/Source/WebCore/ChangeLog	2022-05-04 08:31:55 UTC (rev 293765)
+++ trunk/Source/WebCore/ChangeLog	2022-05-04 08:33:48 UTC (rev 293766)
@@ -1,3 +1,17 @@
+2022-05-04  Megan Gardner  <megan_gard...@apple.com>
+
+        Enable TextCheckingType::Correction on MacCatalyst.
+        https://bugs.webkit.org/show_bug.cgi?id=240036
+
+        Reviewed by Wenson Hsieh.
+
+        Add TextCheckingType::Correction to Catalyst to bring consistency to macOS.
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::markMisspellingsAfterTypingToWord):
+        (WebCore::Editor::markAndReplaceFor):
+        (WebCore::Editor::resolveTextCheckingTypeMask):
+
 2022-05-04  Fujii Hironori  <hironori.fu...@sony.com>
 
         [WinCairo] Crash during MediaPlayerPrivateMediaFoundation::removeListener in the async callback thread

Modified: trunk/Source/WebCore/editing/Editor.cpp (293765 => 293766)


--- trunk/Source/WebCore/editing/Editor.cpp	2022-05-04 08:31:55 UTC (rev 293765)
+++ trunk/Source/WebCore/editing/Editor.cpp	2022-05-04 08:33:48 UTC (rev 293766)
@@ -2546,6 +2546,7 @@
 #if ENABLE(MAC_CATALYST_GRAMMAR_CHECKING)
     if (isGrammarCheckingEnabled()) {
         textCheckingOptions.add(TextCheckingType::Grammar);
+        textCheckingOptions.add(TextCheckingType::Correction);
         auto sentenceStart = startOfSentence(wordStart);
         auto sentenceEnd = endOfSentence(wordStart);
         VisibleSelection fullSentence(sentenceStart, sentenceEnd);
@@ -2860,6 +2861,7 @@
     }
 
     int offsetDueToReplacement = 0;
+    Vector<CharacterRange> previousGrammarRanges;
 
     for (unsigned i = 0; i < results.size(); i++) {
         auto spellingRangeEndOffset = paragraph.checkingEnd() + offsetDueToReplacement;
@@ -2872,6 +2874,16 @@
         const String& replacement = results[i].replacement;
         bool resultEndsAtAmbiguousBoundary = useAmbiguousBoundaryOffset && selectionOffset - 1 <= resultEndLocation;
 
+        bool resultRangeIsAcceptableForReplacement = automaticReplacementStartLocation <= resultEndLocation && resultEndLocation <= automaticReplacementEndLocation;
+        // In this case the result range just has to touch the automatic replacement range, so we can handle replacing non-word text such as punctuation.
+#if ENABLE(MAC_CATALYST_GRAMMAR_CHECKING)
+        if (!resultRangeIsAcceptableForReplacement && shouldMarkGrammar && shouldCheckForCorrection && resultType == TextCheckingType::Correction) {
+            resultRangeIsAcceptableForReplacement = previousGrammarRanges.containsIf([&](auto& range) {
+                return range.location == resultLocation && range.length == resultLength;
+            });
+        }
+#endif
+
         // Only mark misspelling if:
         // 1. Current text checking isn't done for autocorrection, in which case shouldMarkSpelling is false.
         // 2. Result falls within spellingRange.
@@ -2891,11 +2903,10 @@
                 if (paragraph.checkingRangeCovers({ resultLocation + detail.range.location, detail.range.length })) {
                     auto badGrammarRange = paragraph.subrange({ resultLocation + detail.range.location, detail.range.length });
                     addMarker(badGrammarRange, DocumentMarker::Grammar, detail.userDescription);
+                    previousGrammarRanges.append(CharacterRange(resultLocation + detail.range.location, detail.range.length));
                 }
             }
-        } else if (automaticReplacementStartLocation <= resultEndLocation && resultEndLocation <= automaticReplacementEndLocation
-            && isAutomaticTextReplacementType(resultType)) {
-            // In this case the result range just has to touch the automatic replacement range, so we can handle replacing non-word text such as punctuation.
+        } else if (resultRangeIsAcceptableForReplacement && isAutomaticTextReplacementType(resultType)) {
             ASSERT(resultLength > 0);
 
             if (shouldShowCorrectionPanel && (resultEndLocation < automaticReplacementEndLocation
@@ -3924,6 +3935,8 @@
 #if !PLATFORM(IOS_FAMILY)
     bool shouldShowCorrectionPanel = textCheckingOptions.contains(TextCheckingType::ShowCorrectionPanel);
     bool shouldCheckForCorrection = shouldShowCorrectionPanel || textCheckingOptions.contains(TextCheckingType::Correction);
+#else
+    bool shouldCheckForCorrection = textCheckingOptions.contains(TextCheckingType::Correction);
 #endif
 
     OptionSet<TextCheckingType> checkingTypes;
@@ -3931,9 +3944,9 @@
         checkingTypes.add(TextCheckingType::Spelling);
     if (shouldMarkGrammar)
         checkingTypes.add(TextCheckingType::Grammar);
-#if !PLATFORM(IOS_FAMILY)
     if (shouldCheckForCorrection)
         checkingTypes.add(TextCheckingType::Correction);
+#if !PLATFORM(IOS_FAMILY)
     if (shouldShowCorrectionPanel)
         checkingTypes.add(TextCheckingType::ShowCorrectionPanel);
 

Modified: trunk/Source/WebKit/ChangeLog (293765 => 293766)


--- trunk/Source/WebKit/ChangeLog	2022-05-04 08:31:55 UTC (rev 293765)
+++ trunk/Source/WebKit/ChangeLog	2022-05-04 08:33:48 UTC (rev 293766)
@@ -1,3 +1,15 @@
+2022-05-04  Megan Gardner  <megan_gard...@apple.com>
+
+        Enable TextCheckingType::Correction on MacCatalyst.
+        https://bugs.webkit.org/show_bug.cgi?id=240036
+
+        Reviewed by Wenson Hsieh.
+
+        Add TextCheckingType::Correction to Catalyst to bring consistency to macOS.
+
+        * UIProcess/ios/TextCheckerIOS.mm:
+        (WebKit::TextChecker::checkTextOfParagraph):
+
 2022-05-04  Kimmo Kinnunen  <kkinnu...@apple.com>
 
         RemoteImageBuffer ThreadSafeImageBufferFlusher hangs if GPU process crashes

Modified: trunk/Source/WebKit/UIProcess/ios/TextCheckerIOS.mm (293765 => 293766)


--- trunk/Source/WebKit/UIProcess/ios/TextCheckerIOS.mm	2022-05-04 08:31:55 UTC (rev 293765)
+++ trunk/Source/WebKit/UIProcess/ios/TextCheckerIOS.mm	2022-05-04 08:33:48 UTC (rev 293766)
@@ -228,6 +228,8 @@
             types |= NSTextCheckingTypeSpelling;
         if (checkingTypes.contains(TextCheckingType::Grammar))
             types |= NSTextCheckingTypeGrammar;
+        if (checkingTypes.contains(TextCheckingType::Correction))
+            types |= NSTextCheckingTypeCorrection;
         NSDictionary *options = @{
             @"InsertionPoint" : @(insertionPoint)
         };
@@ -265,6 +267,12 @@
                     result.details.uncheckedAppend(WTFMove(detail));
                 }
                 results.append(WTFMove(result));
+            } else if (resultType == NSTextCheckingTypeCorrection && checkingTypes.contains(TextCheckingType::Correction)) {
+                TextCheckingResult result;
+                result.type = TextCheckingType::Correction;
+                result.range = resultRange;
+                result.replacement = [incomingResult replacementString];
+                results.append(WTFMove(result));
             }
         }
     } else
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to