Title: [292385] trunk/Source/WebKit
Revision
292385
Author
megan_gard...@apple.com
Date
2022-04-05 01:36:06 -0700 (Tue, 05 Apr 2022)

Log Message

Expand autocorrect context for more accurate results.
https://bugs.webkit.org/show_bug.cgi?id=237990

Reviewed by Wenson Hsieh.

Covered by existing tests.

Expand autocorrect context to at least 10 words instead of 3, and with a min/max length of 40/100
instead of 12/30 and start context at the beginning of sentences to help with having more accurate
autocorrect suggestions.

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::autocorrectionContext):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (292384 => 292385)


--- trunk/Source/WebKit/ChangeLog	2022-04-05 08:21:52 UTC (rev 292384)
+++ trunk/Source/WebKit/ChangeLog	2022-04-05 08:36:06 UTC (rev 292385)
@@ -1,3 +1,19 @@
+2022-04-05  Megan Gardner  <megan_gard...@apple.com>
+
+        Expand autocorrect context for more accurate results.
+        https://bugs.webkit.org/show_bug.cgi?id=237990
+
+        Reviewed by Wenson Hsieh.
+
+        Covered by existing tests.
+
+        Expand autocorrect context to at least 10 words instead of 3, and with a min/max length of 40/100 
+        instead of 12/30 and start context at the beginning of sentences to help with having more accurate 
+        autocorrect suggestions.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::autocorrectionContext):
+
 2022-04-05  Tim Horton  <timothy_hor...@apple.com>
 
         Remove system feature flags implementation

Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (292384 => 292385)


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2022-04-05 08:21:52 UTC (rev 292384)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2022-04-05 08:36:06 UTC (rev 292385)
@@ -2565,9 +2565,9 @@
     Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     VisiblePosition startPosition = frame->selection().selection().start();
     VisiblePosition endPosition = frame->selection().selection().end();
-    const unsigned minContextWordCount = 3;
-    const unsigned minContextLength = 12;
-    const unsigned maxContextLength = 30;
+    const unsigned minContextWordCount = 10;
+    const unsigned minContextLength = 40;
+    const unsigned maxContextLength = 100;
 
     if (frame->selection().isRange())
         selectedText = plainTextForContext(frame->selection().selection().toNormalizedRange());
@@ -2598,7 +2598,10 @@
                     break;
                 contextStartPosition = previousPosition;
             }
-            if (contextStartPosition.isNotNull() && contextStartPosition != startPosition) {
+            VisiblePosition sentenceContextStartPosition = startOfSentence(startPosition);
+            if (sentenceContextStartPosition.isNotNull() && sentenceContextStartPosition < contextStartPosition)
+                contextStartPosition = sentenceContextStartPosition;
+            if (contextStartPosition.isNotNull() && contextStartPosition < startPosition) {
                 contextBefore = plainTextForContext(makeSimpleRange(contextStartPosition, startPosition));
                 if (atBoundaryOfGranularity(contextStartPosition, TextGranularity::ParagraphGranularity, SelectionDirection::Backward) && firstPositionInEditableContent != contextStartPosition)
                     contextBefore = makeString("\n "_s, contextBefore);
@@ -2606,10 +2609,9 @@
         }
 
         if (endPosition != endOfEditableContent(endPosition)) {
-            VisiblePosition nextPosition;
-            if (!atBoundaryOfGranularity(endPosition, TextGranularity::WordGranularity, SelectionDirection::Forward) && withinTextUnitOfGranularity(endPosition, TextGranularity::WordGranularity, SelectionDirection::Forward))
-                nextPosition = positionOfNextBoundaryOfGranularity(endPosition, TextGranularity::WordGranularity, SelectionDirection::Forward);
-            contextAfter = plainTextForContext(makeSimpleRange(endPosition, nextPosition));
+            VisiblePosition nextPosition = endOfSentence(endPosition);
+            if (nextPosition.isNotNull() && nextPosition > endPosition)
+                contextAfter = plainTextForContext(makeSimpleRange(endPosition, nextPosition));
         }
     }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to