⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 249145 in webkit


Ignore:
Timestamp:
Aug 27, 2019, 9:19:34 AM (7 years ago)
Author:
Alan Coon
Message:

Cherry-pick r249074. rdar://problem/54735492

[iOS] [WebKit2] Tapping on the “I’m” text suggestion after typing “i’” does nothing
https://bugs.webkit.org/show_bug.cgi?id=201085
<rdar://problem/53056118>

Reviewed by Tim Horton.

Source/WebCore:

Exposes an existing quote folding function as a helper on TextIterator, and also adjusts foldQuoteMarks to take
a const String& rather than a String. See WebKit ChangeLog for more details.

  • editing/TextIterator.cpp: (WebCore::foldQuoteMarks): (WebCore::SearchBuffer::SearchBuffer):
  • editing/TextIterator.h:

Source/WebKit:

Currently, logic in applyAutocorrectionInternal only selects the range to autocorrect if the text of the range
matches the string to replace (delivered to us from UIKit). In the case of changing "I’" to "I’m", the string to
replace is "I'" (with a straight quote rather than an apostrophe), even though the DOM contains an apostrophe.

This is because kbd believes that the document context contains straight quotes (rather than apostrophes). For
native text views, this works out because UIKit uses relative UITextPositions to determine the replacement
range rather than by checking against the contents of the document. However, WKWebView does not have the ability
to synchronously compute and reason about arbitrary UITextPositions relative to the selection, so we instead
search for the string near the current selection when applying autocorrections.

Of course, this doesn't work in this scenario because the replacement string contains a straight quote, yet the
text node contains an apostrophe, so we bail and don't end up replacing any text. To address this, we repurpose
TextIterator helpers currently used to allow find-in-page to match straight quotes against apostrophes; instead
of matching the replacement string exactly, we instead match the quote-folded versions of these strings when
finding the range to replace.

Test: fast/events/ios/autocorrect-with-apostrophe.html

  • WebProcess/WebPage/ios/WebPageIOS.mm: (WebKit::WebPage::applyAutocorrectionInternal):

LayoutTests:

Add a new layout test to verify that "I’" can be autocorrected to "I’m".

  • fast/events/ios/autocorrect-with-apostrophe-expected.txt: Added.
  • fast/events/ios/autocorrect-with-apostrophe.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249074 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Location:
branches/safari-608-branch
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-608-branch/LayoutTests/ChangeLog

    r249050 r249145  
     12019-08-27  Alan Coon  <alancoon@apple.com>
     2
     3        Cherry-pick r249074. rdar://problem/54735492
     4
     5    [iOS] [WebKit2] Tapping on the “I’m” text suggestion after typing “i’” does nothing
     6    https://bugs.webkit.org/show_bug.cgi?id=201085
     7    <rdar://problem/53056118>
     8   
     9    Reviewed by Tim Horton.
     10   
     11    Source/WebCore:
     12   
     13    Exposes an existing quote folding function as a helper on TextIterator, and also adjusts foldQuoteMarks to take
     14    a const String& rather than a String. See WebKit ChangeLog for more details.
     15   
     16    * editing/TextIterator.cpp:
     17    (WebCore::foldQuoteMarks):
     18    (WebCore::SearchBuffer::SearchBuffer):
     19    * editing/TextIterator.h:
     20   
     21    Source/WebKit:
     22   
     23    Currently, logic in applyAutocorrectionInternal only selects the range to autocorrect if the text of the range
     24    matches the string to replace (delivered to us from UIKit). In the case of changing "I’" to "I’m", the string to
     25    replace is "I'" (with a straight quote rather than an apostrophe), even though the DOM contains an apostrophe.
     26   
     27    This is because kbd believes that the document context contains straight quotes (rather than apostrophes). For
     28    native text views, this works out because UIKit uses relative UITextPositions to determine the replacement
     29    range rather than by checking against the contents of the document. However, WKWebView does not have the ability
     30    to synchronously compute and reason about arbitrary UITextPositions relative to the selection, so we instead
     31    search for the string near the current selection when applying autocorrections.
     32   
     33    Of course, this doesn't work in this scenario because the replacement string contains a straight quote, yet the
     34    text node contains an apostrophe, so we bail and don't end up replacing any text. To address this, we repurpose
     35    TextIterator helpers currently used to allow find-in-page to match straight quotes against apostrophes; instead
     36    of matching the replacement string exactly, we instead match the quote-folded versions of these strings when
     37    finding the range to replace.
     38   
     39    Test: fast/events/ios/autocorrect-with-apostrophe.html
     40   
     41    * WebProcess/WebPage/ios/WebPageIOS.mm:
     42    (WebKit::WebPage::applyAutocorrectionInternal):
     43   
     44    LayoutTests:
     45   
     46    Add a new layout test to verify that "I’" can be autocorrected to "I’m".
     47   
     48    * fast/events/ios/autocorrect-with-apostrophe-expected.txt: Added.
     49    * fast/events/ios/autocorrect-with-apostrophe.html: Added.
     50   
     51   
     52    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249074 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     53
     54    2019-08-23  Wenson Hsieh  <wenson_hsieh@apple.com>
     55
     56            [iOS] [WebKit2] Tapping on the “I’m” text suggestion after typing “i’” does nothing
     57            https://bugs.webkit.org/show_bug.cgi?id=201085
     58            <rdar://problem/53056118>
     59
     60            Reviewed by Tim Horton.
     61
     62            Add a new layout test to verify that "I’" can be autocorrected to "I’m".
     63
     64            * fast/events/ios/autocorrect-with-apostrophe-expected.txt: Added.
     65            * fast/events/ios/autocorrect-with-apostrophe.html: Added.
     66
    1672019-08-23  Ryan Haddad  <ryanhaddad@apple.com>
    268
  • branches/safari-608-branch/Source/WebCore/ChangeLog

    r249144 r249145  
     12019-08-27  Alan Coon  <alancoon@apple.com>
     2
     3        Cherry-pick r249074. rdar://problem/54735492
     4
     5    [iOS] [WebKit2] Tapping on the “I’m” text suggestion after typing “i’” does nothing
     6    https://bugs.webkit.org/show_bug.cgi?id=201085
     7    <rdar://problem/53056118>
     8   
     9    Reviewed by Tim Horton.
     10   
     11    Source/WebCore:
     12   
     13    Exposes an existing quote folding function as a helper on TextIterator, and also adjusts foldQuoteMarks to take
     14    a const String& rather than a String. See WebKit ChangeLog for more details.
     15   
     16    * editing/TextIterator.cpp:
     17    (WebCore::foldQuoteMarks):
     18    (WebCore::SearchBuffer::SearchBuffer):
     19    * editing/TextIterator.h:
     20   
     21    Source/WebKit:
     22   
     23    Currently, logic in applyAutocorrectionInternal only selects the range to autocorrect if the text of the range
     24    matches the string to replace (delivered to us from UIKit). In the case of changing "I’" to "I’m", the string to
     25    replace is "I'" (with a straight quote rather than an apostrophe), even though the DOM contains an apostrophe.
     26   
     27    This is because kbd believes that the document context contains straight quotes (rather than apostrophes). For
     28    native text views, this works out because UIKit uses relative UITextPositions to determine the replacement
     29    range rather than by checking against the contents of the document. However, WKWebView does not have the ability
     30    to synchronously compute and reason about arbitrary UITextPositions relative to the selection, so we instead
     31    search for the string near the current selection when applying autocorrections.
     32   
     33    Of course, this doesn't work in this scenario because the replacement string contains a straight quote, yet the
     34    text node contains an apostrophe, so we bail and don't end up replacing any text. To address this, we repurpose
     35    TextIterator helpers currently used to allow find-in-page to match straight quotes against apostrophes; instead
     36    of matching the replacement string exactly, we instead match the quote-folded versions of these strings when
     37    finding the range to replace.
     38   
     39    Test: fast/events/ios/autocorrect-with-apostrophe.html
     40   
     41    * WebProcess/WebPage/ios/WebPageIOS.mm:
     42    (WebKit::WebPage::applyAutocorrectionInternal):
     43   
     44    LayoutTests:
     45   
     46    Add a new layout test to verify that "I’" can be autocorrected to "I’m".
     47   
     48    * fast/events/ios/autocorrect-with-apostrophe-expected.txt: Added.
     49    * fast/events/ios/autocorrect-with-apostrophe.html: Added.
     50   
     51   
     52    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249074 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     53
     54    2019-08-23  Wenson Hsieh  <wenson_hsieh@apple.com>
     55
     56            [iOS] [WebKit2] Tapping on the “I’m” text suggestion after typing “i’” does nothing
     57            https://bugs.webkit.org/show_bug.cgi?id=201085
     58            <rdar://problem/53056118>
     59
     60            Reviewed by Tim Horton.
     61
     62            Exposes an existing quote folding function as a helper on TextIterator, and also adjusts foldQuoteMarks to take
     63            a const String& rather than a String. See WebKit ChangeLog for more details.
     64
     65            * editing/TextIterator.cpp:
     66            (WebCore::foldQuoteMarks):
     67            (WebCore::SearchBuffer::SearchBuffer):
     68            * editing/TextIterator.h:
     69
    1702019-08-27  Alan Coon  <alancoon@apple.com>
    271
  • branches/safari-608-branch/Source/WebCore/editing/TextIterator.cpp

    r244200 r249145  
    17831783// of doing it in a separate replacement pass here, but ICU doesn't offer a way
    17841784// to add tailoring on top of the locale-specific tailoring as of this writing.
    1785 static inline String foldQuoteMarks(String string)
    1786 {
    1787     string.replace(hebrewPunctuationGeresh, '\'');
    1788     string.replace(hebrewPunctuationGershayim, '"');
    1789     string.replace(leftDoubleQuotationMark, '"');
    1790     string.replace(leftLowDoubleQuotationMark, '"');
    1791     string.replace(leftSingleQuotationMark, '\'');
    1792     string.replace(leftLowSingleQuotationMark, '\'');
    1793     string.replace(rightDoubleQuotationMark, '"');
    1794     string.replace(rightSingleQuotationMark, '\'');
    1795 
    1796     return string;
     1785String foldQuoteMarks(const String& stringToFold)
     1786{
     1787    String result(stringToFold);
     1788    result.replace(hebrewPunctuationGeresh, '\'');
     1789    result.replace(hebrewPunctuationGershayim, '"');
     1790    result.replace(leftDoubleQuotationMark, '"');
     1791    result.replace(leftLowDoubleQuotationMark, '"');
     1792    result.replace(leftSingleQuotationMark, '\'');
     1793    result.replace(leftLowSingleQuotationMark, '\'');
     1794    result.replace(rightDoubleQuotationMark, '"');
     1795    result.replace(rightSingleQuotationMark, '\'');
     1796
     1797    return result;
    17971798}
    17981799
     
    24112412
    24122413inline SearchBuffer::SearchBuffer(const String& target, FindOptions options)
    2413     : m_target(options & CaseInsensitive ? target.foldCase() : target)
     2414    : m_target(foldQuoteMarks(options & CaseInsensitive ? target.foldCase() : target))
    24142415    , m_options(options)
    24152416    , m_buffer(m_target.length())
     
    24202421    ASSERT(!m_target.isEmpty());
    24212422    m_target.replace(noBreakSpace, ' ');
    2422     foldQuoteMarks(m_target);
    24232423}
    24242424
  • branches/safari-608-branch/Source/WebCore/editing/TextIterator.h

    r244200 r249145  
    5555WEBCORE_EXPORT bool hasAnyPlainText(const Range&, TextIteratorBehavior = TextIteratorDefaultBehavior);
    5656bool findPlainText(const String& document, const String&, FindOptions); // Lets us use the search algorithm on a string.
     57WEBCORE_EXPORT String foldQuoteMarks(const String&);
    5758
    5859// FIXME: Move this somewhere else in the editing directory. It doesn't belong here.
  • branches/safari-608-branch/Source/WebKit/ChangeLog

    r249012 r249145  
     12019-08-27  Alan Coon  <alancoon@apple.com>
     2
     3        Cherry-pick r249074. rdar://problem/54735492
     4
     5    [iOS] [WebKit2] Tapping on the “I’m” text suggestion after typing “i’” does nothing
     6    https://bugs.webkit.org/show_bug.cgi?id=201085
     7    <rdar://problem/53056118>
     8   
     9    Reviewed by Tim Horton.
     10   
     11    Source/WebCore:
     12   
     13    Exposes an existing quote folding function as a helper on TextIterator, and also adjusts foldQuoteMarks to take
     14    a const String& rather than a String. See WebKit ChangeLog for more details.
     15   
     16    * editing/TextIterator.cpp:
     17    (WebCore::foldQuoteMarks):
     18    (WebCore::SearchBuffer::SearchBuffer):
     19    * editing/TextIterator.h:
     20   
     21    Source/WebKit:
     22   
     23    Currently, logic in applyAutocorrectionInternal only selects the range to autocorrect if the text of the range
     24    matches the string to replace (delivered to us from UIKit). In the case of changing "I’" to "I’m", the string to
     25    replace is "I'" (with a straight quote rather than an apostrophe), even though the DOM contains an apostrophe.
     26   
     27    This is because kbd believes that the document context contains straight quotes (rather than apostrophes). For
     28    native text views, this works out because UIKit uses relative UITextPositions to determine the replacement
     29    range rather than by checking against the contents of the document. However, WKWebView does not have the ability
     30    to synchronously compute and reason about arbitrary UITextPositions relative to the selection, so we instead
     31    search for the string near the current selection when applying autocorrections.
     32   
     33    Of course, this doesn't work in this scenario because the replacement string contains a straight quote, yet the
     34    text node contains an apostrophe, so we bail and don't end up replacing any text. To address this, we repurpose
     35    TextIterator helpers currently used to allow find-in-page to match straight quotes against apostrophes; instead
     36    of matching the replacement string exactly, we instead match the quote-folded versions of these strings when
     37    finding the range to replace.
     38   
     39    Test: fast/events/ios/autocorrect-with-apostrophe.html
     40   
     41    * WebProcess/WebPage/ios/WebPageIOS.mm:
     42    (WebKit::WebPage::applyAutocorrectionInternal):
     43   
     44    LayoutTests:
     45   
     46    Add a new layout test to verify that "I’" can be autocorrected to "I’m".
     47   
     48    * fast/events/ios/autocorrect-with-apostrophe-expected.txt: Added.
     49    * fast/events/ios/autocorrect-with-apostrophe.html: Added.
     50   
     51   
     52    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249074 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     53
     54    2019-08-23  Wenson Hsieh  <wenson_hsieh@apple.com>
     55
     56            [iOS] [WebKit2] Tapping on the “I’m” text suggestion after typing “i’” does nothing
     57            https://bugs.webkit.org/show_bug.cgi?id=201085
     58            <rdar://problem/53056118>
     59
     60            Reviewed by Tim Horton.
     61
     62            Currently, logic in applyAutocorrectionInternal only selects the range to autocorrect if the text of the range
     63            matches the string to replace (delivered to us from UIKit). In the case of changing "I’" to "I’m", the string to
     64            replace is "I'" (with a straight quote rather than an apostrophe), even though the DOM contains an apostrophe.
     65
     66            This is because kbd believes that the document context contains straight quotes (rather than apostrophes). For
     67            native text views, this works out because UIKit uses relative UITextPositions to determine the replacement
     68            range rather than by checking against the contents of the document. However, WKWebView does not have the ability
     69            to synchronously compute and reason about arbitrary UITextPositions relative to the selection, so we instead
     70            search for the string near the current selection when applying autocorrections.
     71
     72            Of course, this doesn't work in this scenario because the replacement string contains a straight quote, yet the
     73            text node contains an apostrophe, so we bail and don't end up replacing any text. To address this, we repurpose
     74            TextIterator helpers currently used to allow find-in-page to match straight quotes against apostrophes; instead
     75            of matching the replacement string exactly, we instead match the quote-folded versions of these strings when
     76            finding the range to replace.
     77
     78            Test: fast/events/ios/autocorrect-with-apostrophe.html
     79
     80            * WebProcess/WebPage/ios/WebPageIOS.mm:
     81            (WebKit::WebPage::applyAutocorrectionInternal):
     82
    1832019-08-22  Kocsen Chung  <kocsen_chung@apple.com>
    284
  • branches/safari-608-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r249012 r249145  
    23702370    RefPtr<Range> range;
    23712371    String textForRange;
     2372    auto originalTextWithFoldedQuoteMarks = foldQuoteMarks(originalText);
    23722373
    23732374    if (frame.selection().isCaret()) {
     
    23752376        range = wordRangeFromPosition(position);
    23762377        textForRange = plainTextReplacingNoBreakSpace(range.get());
    2377         if (textForRange != originalText) {
     2378        if (foldQuoteMarks(textForRange) != originalTextWithFoldedQuoteMarks) {
    23782379            // Search for the original text before the selection caret.
    23792380            for (size_t i = 0; i < originalText.length(); ++i)
     
    24052406    }
    24062407
    2407     if (textForRange != originalText)
     2408    if (foldQuoteMarks(textForRange) != originalTextWithFoldedQuoteMarks)
    24082409        return false;
    24092410   
Note: See TracChangeset for help on using the changeset viewer.