https://bugs.webkit.org/show_bug.cgi?id=214319
<rdar://problem/65295523>
Source/WebCore:
Reviewed by Wenson Hsieh.
Move the caret to before the text placeholder to match UIKit.
Tests: editing/text-placeholder/caret-before-zero-width-placeholder-in-content-editable-end-of-word.html
editing/text-placeholder/caret-before-zero-width-placeholder-in-content-editable-start-of-word.html
editing/text-placeholder/insert-into-content-editable-and-remove-via-mutation-event.html
* editing/Editor.cpp:
(WebCore::Editor::insertTextPlaceholder): Compute the position before the placeholder in its parent.
This computation can only be done if the placeholder still has a parent. It may not after insertion
because arbitrary JavaScript code can run. If this happens then bail out and return nullptr. Otherwise,
set the new selection.
LayoutTests:
Reviewed by Wenson Hsieh and Simon Fraser (1).
Add some tests.
[1] Simon only reviewed editing/text-placeholder/insert-into-content-editable-and-remove-via-mutation-event.html.
* editing/text-placeholder/caret-before-zero-width-placeholder-in-content-editable-end-of-word-expected.txt: Added.
* editing/text-placeholder/caret-before-zero-width-placeholder-in-content-editable-end-of-word.html: Added.
* editing/text-placeholder/caret-before-zero-width-placeholder-in-content-editable-start-of-word-expected.txt: Added.
* editing/text-placeholder/caret-before-zero-width-placeholder-in-content-editable-start-of-word.html: Added.
* editing/text-placeholder/insert-into-content-editable-and-remove-via-mutation-event-expected.txt: Added.
* editing/text-placeholder/insert-into-content-editable-and-remove-via-mutation-event.html: Added.
* resources/js-test.js:
(shouldBeLessThanOrEqual): Added. Just like shouldBeGreaterThanOrEqual, but for <=.
Canonical link: https://commits.webkit.org/227169@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@264418 268f45cc-cd09-0410-ab3c-d52691b4dbfc