Bug 214331 - Should represent `TextPlaceholderElement` as an `NSTextAttachmentCharacter` instead of a `\n`
Summary: Should represent `TextPlaceholderElement` as an `NSTextAttachmentCharacter` i...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Devin Rousso
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-07-14 16:24 PDT by Devin Rousso
Modified: 2020-07-15 17:37 PDT (History)
9 users (show)

See Also:


Attachments
Patch (13.13 KB, patch)
2020-07-14 16:50 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (14.41 KB, patch)
2020-07-14 17:46 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (14.41 KB, patch)
2020-07-14 17:52 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (11.81 KB, patch)
2020-07-14 18:49 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (12.89 KB, patch)
2020-07-15 10:28 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (13.27 KB, patch)
2020-07-15 12:47 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Devin Rousso 2020-07-14 16:24:19 PDT
This can muck with whitespace addition/removal with iOS smart editing.
Comment 1 Devin Rousso 2020-07-14 16:41:09 PDT
<rdar://problem/64779558>
Comment 2 Devin Rousso 2020-07-14 16:50:56 PDT
Created attachment 404306 [details]
Patch
Comment 3 Devin Rousso 2020-07-14 17:46:04 PDT
Created attachment 404311 [details]
Patch
Comment 4 Devin Rousso 2020-07-14 17:52:22 PDT
Created attachment 404312 [details]
Patch

... stupid semicolons (╯°□°)╯︵ ┻━┻
Comment 5 Wenson Hsieh 2020-07-14 17:55:35 PDT
Comment on attachment 404311 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=404311&action=review

> Source/WebCore/editing/TextIterator.cpp:807
> +static bool shouldEmitReplacementInsteadOfNode(Node& node)

This should probably take `const Node&` as the argument type.

> Source/WebCore/editing/TextIterator.cpp:851
> +    // Placeholders should eventually disappear, so treating them as a line break doesn't make sense
> +    // as when they are removed the text after it is combined with the text before it.

Nit - I think this comment would be more effective inside `shouldEmitReplacementInsteadOfNode`, since that is where the notion of “emitting replacement characters instead of nodes" becomes relevant to `TextPlaceholderElement`.

> Source/WebKit/UIProcess/API/ios/WKWebViewPrivateForTestingIOS.h:61
> +- (void)_insertTextPlaceholderWithSize:(CGSize)size completionHandler:(void (^)(UITextPlaceholder *))completionHandler;
> +- (void)_removeTextPlaceholder:(UITextPlaceholder *)placeholder willInsertText:(BOOL)willInsertText completionHandler:(void (^)(void))completionHandler;

Nit - I think you could actually omit this extra plumbing on WKWebView, and just use -textInputContentView instead to grab the WKContentView (exposed as a <UIWKInteractionViewProtocol>-conformant responder).

> Source/WebKit/UIProcess/API/ios/WKWebViewTestingIOS.mm:117
> +- (void)_insertTextPlaceholderWithSize:(CGSize)size completionHandler:(void (^)(UITextPlaceholder *))completionHandler
> +{
> +    [_contentView insertTextPlaceholderWithSize:size completionHandler:completionHandler];
> +}
> +
> +- (void)_removeTextPlaceholder:(UITextPlaceholder *)placeholder willInsertText:(BOOL)willInsertText completionHandler:(void (^)(void))completionHandler
> +{
> +    [_contentView removeTextPlaceholder:placeholder willInsertText:willInsertText completionHandler:completionHandler];
> +}
> +

(Ditto)

> Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm:863
> +    auto* placeholder = [webView synchronouslyInsertTextPlaceholderWithSize:CGSizeMake(5, 5)];

Nit - the * should be on the other side here. But also, we can just use `auto` for these.

> Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm:880
> +    auto* placeholder = [webView synchronouslyInsertTextPlaceholderWithSize:CGSizeMake(5, 5)];

Ditto.
Comment 6 Wenson Hsieh 2020-07-14 18:15:33 PDT
Comment on attachment 404312 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=404312&action=review

> Source/WebKit/Platform/spi/ios/UIKitSPI.h:708
> +- (void)insertTextPlaceholderWithSize:(CGSize)size completionHandler:(void (^)(UITextPlaceholder *))completionHandler;
> +- (void)removeTextPlaceholder:(UITextPlaceholder *)placeholder willInsertText:(BOOL)willInsertText completionHandler:(void (^)(void))completionHandler;

This should also go inside the `@optional` section, to match the actual SPI header.
Comment 7 Devin Rousso 2020-07-14 18:49:05 PDT
Comment on attachment 404311 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=404311&action=review

>> Source/WebCore/editing/TextIterator.cpp:807
>> +static bool shouldEmitReplacementInsteadOfNode(Node& node)
> 
> This should probably take `const Node&` as the argument type.

I was matching the other `shouldEmit*` functions, but yeah I could do that.
Comment 8 Devin Rousso 2020-07-14 18:49:56 PDT
Created attachment 404314 [details]
Patch
Comment 9 Devin Rousso 2020-07-15 10:28:53 PDT
Created attachment 404355 [details]
Patch
Comment 10 Wenson Hsieh 2020-07-15 11:37:04 PDT
Comment on attachment 404355 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=404355&action=review

> Source/WebCore/ChangeLog:9
> +        Reviewed by NOBODY (OOPS!).
> +
> +        * editing/TextIterator.cpp:

It would be nice to have a few words here to explain why we want to emit the replacement character instead of a newline (something similar to what you already wrote in the comment below).
Comment 11 Devin Rousso 2020-07-15 12:47:40 PDT
Created attachment 404376 [details]
Patch
Comment 12 EWS 2020-07-15 14:16:00 PDT
Committed r264420: <https://trac.webkit.org/changeset/264420>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 404376 [details].
Comment 13 Darin Adler 2020-07-15 14:40:22 PDT
Comment on attachment 404376 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=404376&action=review

> Source/WebCore/editing/TextIterator.cpp:1014
> +            emitCharacter(0xFFFC, *m_node->parentNode(), m_node, 0, 0);

Should write:

    objectReplacementCharacter

Instead of:

    0xFFFC

It’s in the header CharacterNames.h.
Comment 14 Devin Rousso 2020-07-15 15:44:58 PDT
Comment on attachment 404376 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=404376&action=review

>> Source/WebCore/editing/TextIterator.cpp:1014
>> +            emitCharacter(0xFFFC, *m_node->parentNode(), m_node, 0, 0);
> 
> Should write:
> 
>     objectReplacementCharacter
> 
> Instead of:
> 
>     0xFFFC
> 
> It’s in the header CharacterNames.h.

Oh neat!  I did not know that existed :)

Will land a followup.
Comment 15 Devin Rousso 2020-07-15 17:37:31 PDT
Committed r264439: Unreviewed followup, use objectReplacementCharacter instead of 0xFFFC