Title: [250432] trunk
- Revision
- 250432
- Author
- [email protected]
- Date
- 2019-09-27 10:33:25 -0700 (Fri, 27 Sep 2019)
Log Message
[iOS]: When inserting a photo and then inserting auto-corrected text, the photo is removed
https://bugs.webkit.org/show_bug.cgi?id=202294
Patch by Said Abou-Hallawa <[email protected]> on 2019-09-27
Reviewed by Wenson Hsieh.
Source/WebKit:
WebPage::applyAutocorrectionInternal() calls wordRangeFromPosition() to
calculate the range of the word to be replaced with the auto-corrected
word. But if the text of the range does not match the original text,
applyAutocorrectionInternal() tries to correct the range by moving it
forward such that the length of the text range matches the length of the
original text.
Another case, which should correct the range also, is: the range does not
have a text but it is not collapsed. In this case, we should set the range
back to the selection range so non-text nodes is removed.
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::applyAutocorrectionInternal):
LayoutTests:
* fast/events/ios/autocorrect-after-image-expected.txt: Added.
* fast/events/ios/autocorrect-after-image.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (250431 => 250432)
--- trunk/LayoutTests/ChangeLog 2019-09-27 17:14:20 UTC (rev 250431)
+++ trunk/LayoutTests/ChangeLog 2019-09-27 17:33:25 UTC (rev 250432)
@@ -1,3 +1,13 @@
+2019-09-27 Said Abou-Hallawa <[email protected]>
+
+ [iOS]: When inserting a photo and then inserting auto-corrected text, the photo is removed
+ https://bugs.webkit.org/show_bug.cgi?id=202294
+
+ Reviewed by Wenson Hsieh.
+
+ * fast/events/ios/autocorrect-after-image-expected.txt: Added.
+ * fast/events/ios/autocorrect-after-image.html: Added.
+
2019-09-27 John Wilander <[email protected]>
Storage Access API: document.hasStorageAccess() should return false by default
Added: trunk/LayoutTests/fast/events/ios/autocorrect-after-image-expected.txt (0 => 250432)
--- trunk/LayoutTests/fast/events/ios/autocorrect-after-image-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/events/ios/autocorrect-after-image-expected.txt 2019-09-27 17:33:25 UTC (rev 250432)
@@ -0,0 +1,13 @@
+The
+This test verifies that inserting an auto-corrected text after an image does not remove the image.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS Observed input event of inputType insertText
+PASS document.activeElement is editor
+PASS editor.children.length is 1
+PASS editor.children[0] instanceof HTMLImageElement is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/events/ios/autocorrect-after-image.html (0 => 250432)
--- trunk/LayoutTests/fast/events/ios/autocorrect-after-image.html (rev 0)
+++ trunk/LayoutTests/fast/events/ios/autocorrect-after-image.html 2019-09-27 17:33:25 UTC (rev 250432)
@@ -0,0 +1,44 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+<html>
+<head>
+ <meta charset="utf8">
+ <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
+ <script src=""
+ <script src=""
+ <style>
+ #editor {
+ max-width: 200px;
+ }
+ </style>
+ <script>
+ jsTestIsAsync = true;
+
+ addEventListener("load", async () => {
+ description(`This test verifies that inserting an auto-corrected text after an image does not remove the image.`);
+
+ addEventListener("input", event => testPassed(`Observed input event of inputType ${event.inputType}`));
+
+ if (!window.testRunner || !testRunner.runUIScript)
+ return;
+
+ editor = document.getElementById("editor");
+ await UIHelper.activateElementAndWaitForInputSession(editor);
+ await UIHelper.applyAutocorrection("The", "");
+ shouldBe("document.activeElement", "editor");
+ shouldBe("editor.children.length", "1");
+ shouldBeTrue("editor.children[0] instanceof HTMLImageElement");
+ editor.blur();
+ await UIHelper.waitForKeyboardToHide();
+ finishJSTest();
+ });
+ </script>
+</head>
+<body>
+ <div contenteditable id="editor">
+ <img src=""
+ </div>
+ <div id="description"></div>
+ <div id="console"></div>
+</body>
+
+</html>
Modified: trunk/Source/WebKit/ChangeLog (250431 => 250432)
--- trunk/Source/WebKit/ChangeLog 2019-09-27 17:14:20 UTC (rev 250431)
+++ trunk/Source/WebKit/ChangeLog 2019-09-27 17:33:25 UTC (rev 250432)
@@ -1,3 +1,24 @@
+2019-09-27 Said Abou-Hallawa <[email protected]>
+
+ [iOS]: When inserting a photo and then inserting auto-corrected text, the photo is removed
+ https://bugs.webkit.org/show_bug.cgi?id=202294
+
+ Reviewed by Wenson Hsieh.
+
+ WebPage::applyAutocorrectionInternal() calls wordRangeFromPosition() to
+ calculate the range of the word to be replaced with the auto-corrected
+ word. But if the text of the range does not match the original text,
+ applyAutocorrectionInternal() tries to correct the range by moving it
+ forward such that the length of the text range matches the length of the
+ original text.
+
+ Another case, which should correct the range also, is: the range does not
+ have a text but it is not collapsed. In this case, we should set the range
+ back to the selection range so non-text nodes is removed.
+
+ * WebProcess/WebPage/ios/WebPageIOS.mm:
+ (WebKit::WebPage::applyAutocorrectionInternal):
+
2019-09-27 John Wilander <[email protected]>
Storage Access API: document.hasStorageAccess() should return false by default
Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (250431 => 250432)
--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2019-09-27 17:14:20 UTC (rev 250431)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2019-09-27 17:33:25 UTC (rev 250432)
@@ -2371,6 +2371,9 @@
VisiblePosition position = frame.selection().selection().start();
range = wordRangeFromPosition(position);
textForRange = plainTextReplacingNoBreakSpace(range.get());
+
+ // If 'originalText' is not the same as 'textForRange' we need to move 'range'
+ // forward such that it matches the original selection as much as possible.
if (foldQuoteMarks(textForRange) != originalTextWithFoldedQuoteMarks) {
// Search for the original text before the selection caret.
for (size_t i = 0; i < originalText.length(); ++i)
@@ -2378,8 +2381,7 @@
if (position.isNull())
position = startOfDocument(static_cast<Node*>(frame.document()->documentElement()));
range = Range::create(*frame.document(), position, frame.selection().selection().start());
- if (range)
- textForRange = (range) ? plainTextReplacingNoBreakSpace(range.get()) : emptyString();
+ textForRange = plainTextReplacingNoBreakSpace(range.get());
unsigned loopCount = 0;
const unsigned maxPositionsAttempts = 10;
while (textForRange.length() && textForRange.length() > originalText.length() && loopCount < maxPositionsAttempts) {
@@ -2388,9 +2390,15 @@
range = nullptr;
else
range = Range::create(*frame.document(), position, frame.selection().selection().start());
- textForRange = (range) ? plainTextReplacingNoBreakSpace(range.get()) : emptyString();
+ textForRange = plainTextReplacingNoBreakSpace(range.get());
loopCount++;
}
+ } else if (textForRange.isEmpty() && range && !range->collapsed()) {
+ // If 'range' does not include any text but it is not collapsed, we need to set
+ // 'range' to match the selection. Otherwise non-text nodes will be removed.
+ range = Range::create(*frame.document(), position, position);
+ if (!range)
+ return false;
}
} else {
// Range selection.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes