Title: [246932] trunk/Source/WebKit
Revision
246932
Author
timothy_hor...@apple.com
Date
2019-06-28 13:14:49 -0700 (Fri, 28 Jun 2019)

Log Message

macCatalyst: Selected range sometimes wrong after autocorrection
https://bugs.webkit.org/show_bug.cgi?id=199299
<rdar://problem/49717224>

Reviewed by Wenson Hsieh.

* UIProcess/Cocoa/TextCheckingController.h:
* UIProcess/Cocoa/TextCheckingController.mm:
(WebKit::TextCheckingController::replaceRelativeToSelection):
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView replaceSelectionOffset:length:withAnnotatedString:relativeReplacementRange:]):
Plumb the whole relative replacement range through to the Web Content process.

* WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.h:
* WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.messages.in:
* WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm:
(WebKit::TextCheckingControllerProxy::replaceRelativeToSelection):
Only replace the text of the substring that changed (the replacement range),
and fix up the selection offset math (it was really just wrong before).

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (246931 => 246932)


--- trunk/Source/WebKit/ChangeLog	2019-06-28 20:12:45 UTC (rev 246931)
+++ trunk/Source/WebKit/ChangeLog	2019-06-28 20:14:49 UTC (rev 246932)
@@ -1,3 +1,25 @@
+2019-06-28  Tim Horton  <timothy_hor...@apple.com>
+
+        macCatalyst: Selected range sometimes wrong after autocorrection
+        https://bugs.webkit.org/show_bug.cgi?id=199299
+        <rdar://problem/49717224>
+
+        Reviewed by Wenson Hsieh.
+
+        * UIProcess/Cocoa/TextCheckingController.h:
+        * UIProcess/Cocoa/TextCheckingController.mm:
+        (WebKit::TextCheckingController::replaceRelativeToSelection):
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView replaceSelectionOffset:length:withAnnotatedString:relativeReplacementRange:]):
+        Plumb the whole relative replacement range through to the Web Content process.
+
+        * WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.h:
+        * WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.messages.in:
+        * WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm:
+        (WebKit::TextCheckingControllerProxy::replaceRelativeToSelection):
+        Only replace the text of the substring that changed (the replacement range),
+        and fix up the selection offset math (it was really just wrong before).
+
 2019-06-28  Wenson Hsieh  <wenson_hs...@apple.com>
 
         Need a way for SPI clients to know when to avoid resizing to accommodate for the input view bounds

Modified: trunk/Source/WebKit/UIProcess/Cocoa/TextCheckingController.h (246931 => 246932)


--- trunk/Source/WebKit/UIProcess/Cocoa/TextCheckingController.h	2019-06-28 20:12:45 UTC (rev 246931)
+++ trunk/Source/WebKit/UIProcess/Cocoa/TextCheckingController.h	2019-06-28 20:14:49 UTC (rev 246932)
@@ -42,7 +42,7 @@
     explicit TextCheckingController(WebPageProxy&);
     ~TextCheckingController() = default;
 
-    void replaceRelativeToSelection(NSAttributedString *annotatedString, int64_t selectionOffset, uint64_t length, bool textChanged);
+    void replaceRelativeToSelection(NSAttributedString *annotatedString, int64_t selectionOffset, uint64_t length, uint64_t relativeReplacementLocation, uint64_t relativeReplacementLength);
     void removeAnnotationRelativeToSelection(NSString *annotationName, int64_t selectionOffset, uint64_t length);
 
 private:

Modified: trunk/Source/WebKit/UIProcess/Cocoa/TextCheckingController.mm (246931 => 246932)


--- trunk/Source/WebKit/UIProcess/Cocoa/TextCheckingController.mm	2019-06-28 20:12:45 UTC (rev 246931)
+++ trunk/Source/WebKit/UIProcess/Cocoa/TextCheckingController.mm	2019-06-28 20:14:49 UTC (rev 246932)
@@ -39,12 +39,12 @@
 {
 }
 
-void TextCheckingController::replaceRelativeToSelection(NSAttributedString *annotatedString, int64_t selectionOffset, uint64_t length, bool textChanged)
+void TextCheckingController::replaceRelativeToSelection(NSAttributedString *annotatedString, int64_t selectionOffset, uint64_t length, uint64_t relativeReplacementLocation, uint64_t relativeReplacementLength)
 {
     if (!m_page.hasRunningProcess())
         return;
 
-    m_page.process().send(Messages::TextCheckingControllerProxy::ReplaceRelativeToSelection(annotatedString, selectionOffset, length, textChanged), m_page.pageID());
+    m_page.process().send(Messages::TextCheckingControllerProxy::ReplaceRelativeToSelection(annotatedString, selectionOffset, length, relativeReplacementLocation, relativeReplacementLength), m_page.pageID());
 }
 
 void TextCheckingController::removeAnnotationRelativeToSelection(NSString *annotationName, int64_t selectionOffset, uint64_t length)

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (246931 => 246932)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-06-28 20:12:45 UTC (rev 246931)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-06-28 20:14:49 UTC (rev 246932)
@@ -5810,7 +5810,7 @@
 #if ENABLE(PLATFORM_DRIVEN_TEXT_CHECKING)
 - (void)replaceSelectionOffset:(NSInteger)selectionOffset length:(NSUInteger)length withAnnotatedString:(NSAttributedString *)annotatedString relativeReplacementRange:(NSRange)relativeReplacementRange
 {
-    _textCheckingController->replaceRelativeToSelection(annotatedString, selectionOffset, length, relativeReplacementRange.location != NSNotFound);
+    _textCheckingController->replaceRelativeToSelection(annotatedString, selectionOffset, length, relativeReplacementRange.location, relativeReplacementRange.length);
 }
 
 - (void)removeAnnotation:(NSAttributedStringKey)annotationName forSelectionOffset:(NSInteger)selectionOffset length:(NSUInteger)length

Modified: trunk/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.h (246931 => 246932)


--- trunk/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.h	2019-06-28 20:12:45 UTC (rev 246931)
+++ trunk/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.h	2019-06-28 20:14:49 UTC (rev 246932)
@@ -64,7 +64,7 @@
     Optional<RangeAndOffset> rangeAndOffsetRelativeToSelection(int64_t offset, uint64_t length);
 
     // Message handlers.
-    void replaceRelativeToSelection(AttributedString, int64_t selectionOffset, uint64_t length, bool textChanged);
+    void replaceRelativeToSelection(AttributedString, int64_t selectionOffset, uint64_t length, uint64_t relativeReplacementLocation, uint64_t relativeReplacementLength);
     void removeAnnotationRelativeToSelection(String annotationName, int64_t selectionOffset, uint64_t length);
 
     WebPage& m_page;

Modified: trunk/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.messages.in (246931 => 246932)


--- trunk/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.messages.in	2019-06-28 20:12:45 UTC (rev 246931)
+++ trunk/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.messages.in	2019-06-28 20:14:49 UTC (rev 246932)
@@ -23,9 +23,9 @@
 #if ENABLE(PLATFORM_DRIVEN_TEXT_CHECKING)
 
 messages -> TextCheckingControllerProxy {
-    ReplaceRelativeToSelection(struct WebKit::AttributedString annotatedString, int64_t selectionOffset, uint64_t length, bool textChanged)
+    ReplaceRelativeToSelection(struct WebKit::AttributedString annotatedString, int64_t selectionOffset, uint64_t length, uint64_t relativeReplacementLocation, uint64_t relativeReplacementLength)
 
     RemoveAnnotationRelativeToSelection(String annotationName, int64_t selectionOffset, uint64_t length)
 }
 
-#endif
\ No newline at end of file
+#endif

Modified: trunk/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm (246931 => 246932)


--- trunk/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm	2019-06-28 20:12:45 UTC (rev 246931)
+++ trunk/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm	2019-06-28 20:14:49 UTC (rev 246932)
@@ -90,7 +90,7 @@
     return {{ TextIterator::rangeFromLocationAndLength(root, selectionLocation, length), selectionLocation }};
 }
 
-void TextCheckingControllerProxy::replaceRelativeToSelection(AttributedString annotatedString, int64_t selectionOffset, uint64_t length, bool textChanged)
+void TextCheckingControllerProxy::replaceRelativeToSelection(AttributedString annotatedString, int64_t selectionOffset, uint64_t length, uint64_t relativeReplacementLocation, uint64_t relativeReplacementLength)
 {
     Frame& frame = m_page.corePage()->focusController().focusedOrMainFrame();
     FrameSelection& frameSelection = frame.selection();
@@ -107,16 +107,20 @@
     auto& markers = frame.document()->markers();
     markers.removeMarkers(*range, relevantMarkerTypes());
 
-    if (textChanged) {
-        bool restoreSelection = frameSelection.selection().isRange();
+    if (relativeReplacementLocation != NSNotFound) {
+        auto rangeAndOffsetOfReplacement = rangeAndOffsetRelativeToSelection(selectionOffset + relativeReplacementLocation, relativeReplacementLength);
+        if (rangeAndOffsetOfReplacement) {
+            auto replacementRange = rangeAndOffsetOfReplacement->range;
+            if (replacementRange) {
+                bool restoreSelection = frameSelection.selection().isRange();
+                frame.editor().replaceRangeForSpellChecking(*replacementRange, [[annotatedString.string string] substringWithRange:NSMakeRange(relativeReplacementLocation, relativeReplacementLength)]);
 
-        frame.editor().replaceRangeForSpellChecking(*range, [annotatedString.string string]);
-
-        size_t selectionLocationToRestore = locationInRoot - selectionOffset;
-        if (restoreSelection && selectionLocationToRestore > locationInRoot + length) {
-            selectionLocationToRestore -= locationInRoot - length;
-            auto selectionToRestore = TextIterator::rangeFromLocationAndLength(root, selectionLocationToRestore, 0);
-            frameSelection.moveTo(selectionToRestore.get());
+                size_t selectionLocationToRestore = locationInRoot - selectionOffset;
+                if (restoreSelection && selectionLocationToRestore > locationInRoot + relativeReplacementLocation + relativeReplacementLength) {
+                    auto selectionToRestore = TextIterator::rangeFromLocationAndLength(root, selectionLocationToRestore, 0);
+                    frameSelection.moveTo(selectionToRestore.get());
+                }
+            }
         }
     }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to