<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>212098</bug_id>
          
          <creation_ts>2020-05-19 11:56:47 -0700</creation_ts>
          <short_desc>Inserting a no-break space before or after a marker removes the marker</short_desc>
          <delta_ts>2020-05-20 08:57:17 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore Misc.</component>
          <version>WebKit Local Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=212097</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Daniel Bates">dbates</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1654114</commentid>
    <comment_count>0</comment_count>
    <who name="Daniel Bates">dbates</who>
    <bug_when>2020-05-19 11:56:47 -0700</bug_when>
    <thetext>This affects all markers by code inspection, but is user visible with a dictation alternative marker. (Not user visible with spelling and grammar markers because engine re-runs spell check, which masks the bug).

Steps to reproduce:
1. Add the following test case:

[[

#include &quot;config.h&quot;

#if PLATFORM(IOS_FAMILY)

#import &quot;PlatformUtilities.h&quot;
#import &quot;TestInputDelegate.h&quot;
#import &quot;TestWKWebView.h&quot;
#import &quot;UIKitSPI.h&quot;
#import &quot;WKWebViewConfigurationExtras.h&quot;
#import &lt;WebKit/WKWebViewPrivate.h&gt;
#import &lt;wtf/unicode/CharacterNames.h&gt;

namespace TestWebKitAPI {

static inline NSString *makeNSStringWithCharacter(unichar c)
{
    return [NSString stringWithCharacters:&amp;c length:1];
};

TEST(InsertTextAlternatives, InsertLeadingNoBreakSpace)
{
    auto *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@&quot;WebProcessPlugInWithInternals&quot; configureJSCForTesting:YES];
    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration]);
    auto inputDelegate = adoptNS([[TestInputDelegate alloc] init]);
    [inputDelegate setFocusStartsInputSessionPolicyHandler:[] (WKWebView *, id &lt;_WKFocusedElementInfo&gt;) { return _WKFocusStartsInputSessionPolicyAllow; }];
    [webView _setInputDelegate:inputDelegate.get()];

    [webView synchronouslyLoadHTMLString:@&quot;&lt;body contenteditable=&apos;true&apos;&gt;&lt;/body&gt;&quot;];
    [webView evaluateJavaScriptAndWaitForInputSessionToChange:@&quot;document.body.focus()&quot;];
    [[webView textInputContentView] insertText:@&quot;hello&quot; alternatives:@[@&quot;yellow&quot;] style:UITextAlternativeStyleNone];
    [webView waitForNextPresentationUpdate];

    [webView _synchronouslyExecuteEditCommand:@&quot;MoveToBeginningOfDocument&quot; argument:nil];
    [[webView textInputContentView] insertText:makeNSStringWithCharacter(noBreakSpace)];
    [webView _synchronouslyExecuteEditCommand:@&quot;MoveToBeginningOfDocument&quot; argument:nil];
    [webView waitForNextPresentationUpdate];

    EXPECT_FALSE([[webView objectByEvaluatingJavaScript:@&quot;internals.hasDictationAlternativesMarker(0, 1)&quot;] boolValue]); // &lt;no-break space&gt;
    EXPECT_TRUE([[webView objectByEvaluatingJavaScript:@&quot;internals.hasDictationAlternativesMarker(1, 5)&quot;] boolValue]); // hello
}

TEST(InsertTextAlternatives, InsertTrailingNoBreakSpace)
{
    auto *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@&quot;WebProcessPlugInWithInternals&quot; configureJSCForTesting:YES];
    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration]);
    auto inputDelegate = adoptNS([[TestInputDelegate alloc] init]);
    [inputDelegate setFocusStartsInputSessionPolicyHandler:[] (WKWebView *, id &lt;_WKFocusedElementInfo&gt;) { return _WKFocusStartsInputSessionPolicyAllow; }];
    [webView _setInputDelegate:inputDelegate.get()];

    [webView synchronouslyLoadHTMLString:@&quot;&lt;body contenteditable=&apos;true&apos;&gt;&lt;/body&gt;&quot;];
    [webView evaluateJavaScriptAndWaitForInputSessionToChange:@&quot;document.body.focus()&quot;];
    [[webView textInputContentView] insertText:@&quot;hello&quot; alternatives:@[@&quot;yellow&quot;] style:UITextAlternativeStyleNone];
    [[webView textInputContentView] insertText:makeNSStringWithCharacter(noBreakSpace)];
    [webView _synchronouslyExecuteEditCommand:@&quot;MoveToBeginningOfDocument&quot; argument:nil];
    [webView waitForNextPresentationUpdate];

    EXPECT_TRUE([[webView objectByEvaluatingJavaScript:@&quot;internals.hasDictationAlternativesMarker(0, 5)&quot;] boolValue]); // hello
    EXPECT_FALSE([[webView objectByEvaluatingJavaScript:@&quot;internals.hasDictationAlternativesMarker(5, 1)&quot;] boolValue]); // &lt;no-break space&gt;
}

} // namespace TestWebKitAPI

#endif // PLATFORM(IOS_FAMILY)
]]

2.Run them

Then InsertLeadingNoBreakSpace fails because of:

EXPECT_TRUE([[webView objectByEvaluatingJavaScript:@&quot;internals.hasDictationAlternativesMarker(1, 5)&quot;] boolValue]); // hello

And InsertTrailingNoBreakSpace because of:

EXPECT_TRUE([[webView objectByEvaluatingJavaScript:@&quot;internals.hasDictationAlternativesMarker(0, 5)&quot;] boolValue]); // hello</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1654462</commentid>
    <comment_count>1</comment_count>
    <who name="Daniel Bates">dbates</who>
    <bug_when>2020-05-20 08:57:17 -0700</bug_when>
    <thetext>I committed failing version of ^^^ in bug #212097.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>