Skip to content
Permalink
Browse files
Add a nbsp at the the end of the text when the next text has a leadin…
…g space

Add a nbsp at the the end of the text when the next text has a leading space
https://bugs.webkit.org/show_bug.cgi?id=248723

Reviewed by Ryosuke Niwa.

This patch is to fix three regressions stemming from 257136@main.

1) Breaking chat window or login forms while trying to press 'space' key.
2) Add nbsp instead of plain space between text nodes in case next text node has a leading plain space.
3) Not accounting for all kind of whitespaces including "Enter"

These are merge of following Blink commits:

> https://chromium.googlesource.com/chromium/src.git/+/4dab74137593abb0888e415294aeb80da27362e3
> https://chromium.googlesource.com/chromium/src.git/+/9ebff223d5d639167c3efb01a5fa912b3aee05a9
> https://chromium.googlesource.com/chromium/src.git/+/5b9a9a6f8c9c646ac542a9e1a2f18c59140849e6

* Source/WebCore/editing/CompositeEditingCommand.cpp:
(CompositeEditCommand::rebalanceWhitespaceOnTextSubtring):
(1) Add logic to account for leading space (including "Enter" key)
(2) accept "Space" Key
(3) Refactor code by introducing const bool "nextSiblingIsTextNodeWithoutLeadingSpace"
* LayoutTests/resources/assert-selection.js: Added Test Script with Chromium Copyright header
* LayoutTests/editing/inserting/insert-space.html: Added Test Case
* LayoutTests/editing/inserting/insert-space-expected.txt: Added Test Case Expectation

Canonical link: https://commits.webkit.org/257622@main
  • Loading branch information
Ahmad-S792 authored and Ahmad Saleem committed Dec 9, 2022
1 parent 1a7b36e commit 41ea6427c93797b6c7aceb36d05329618ddd87b9
Show file tree
Hide file tree
Showing 4 changed files with 772 additions and 2 deletions.
@@ -0,0 +1,18 @@


Harness Error (FAIL), message = Test named "Insert a   instead of plain space when it is inserted before the text node that has a leading plain space" passed a function to `test` that returned a value.

PASS insert a plain space in the middle of text node
PASS insert a plain space between two inserted text nodes
PASS Insert a   instead of plain space when it is inserted before the empty text node
PASS Insert a   instead of plain space when it is inserted before the text node that has a leading plain space
FAIL Insert spaces into the editable <div> that only has <br> and space as child LayoutTests/resources/assert-selection.js:588:30
expected <div contenteditable>   | </div>,
but got <div contenteditable>   |</div>,
sameupto <div contenteditable>   |
FAIL Insert spaces into the editable <div> that only has <br> and enter as child LayoutTests/resources/assert-selection.js:588:30
expected <div contenteditable>   |
</div>,
but got <div contenteditable>   |</div>,
sameupto <div contenteditable>   |

@@ -0,0 +1,70 @@
<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../../resources/assert-selection.js"></script>
<script>
test(() => assert_selection(
'<div contenteditable><p>A|B</p></div>',
'insertText \ ',
'<div contenteditable><p>A |B</p></div>'),
'insert a plain space in the middle of text node');

test(() => assert_selection(
'<div contenteditable><p id="para"></p></div>',
selection => {
var para = selection.document.getElementById('para');
para.appendChild(selection.document.createTextNode('A'));
para.appendChild(selection.document.createTextNode('B'));
selection.collapse(para.firstChild, 1);

selection.document.execCommand('insertText', false, ' ');
},
'<div contenteditable><p id="para">A |B</p></div>'),
'insert a plain space between two inserted text nodes');

test(() => assert_selection(
'<div contenteditable><p id="para"></p></div>',
selection => {
var para = selection.document.getElementById('para');
para.appendChild(selection.document.createTextNode('A'));
para.appendChild(selection.document.createTextNode(''));
selection.collapse(para.firstChild, 1);

selection.document.execCommand('insertText', false, ' ');
},
'<div contenteditable><p id="para">A\u00A0|</p></div>'),
'Insert a &nbsp; instead of plain space when it is inserted before the empty text node');

test(() => assert_selection(
'<div contenteditable><p id="para"></p></div>',
selection => {
var para = selection.document.getElementById('para');
para.appendChild(selection.document.createTextNode('A'));
para.appendChild(selection.document.createTextNode(' B'));
selection.collapse(para.firstChild, 1);

selection.document.execCommand('insertText', false, ' ');
},
'<div contenteditable><p id="para">A\u00A0| B</p></div>'),
'Insert a &nbsp; instead of plain space when it is inserted before the text node that has a leading plain space');

test(() => assert_selection(
'<div contenteditable>|<br> </div>',
selection => {
selection.document.execCommand('insertText', false, ' ');
selection.document.execCommand('insertText', false, ' ');
selection.document.execCommand('insertText', false, ' ');
},
'<div contenteditable>\u00A0 \u00A0| </div>'),
'Insert spaces into the editable <div> that only has <br> and space as child');

test(() => assert_selection(
'<div contenteditable>|<br>\u000A</div>',
selection => {
selection.document.execCommand('insertText', false, ' ');
selection.document.execCommand('insertText', false, ' ');
selection.document.execCommand('insertText', false, ' ');
},
'<div contenteditable>\u00A0 \u00A0|\u000A</div>'),
'Insert spaces into the editable <div> that only has <br> and enter as child');
</script>

0 comments on commit 41ea642

Please sign in to comment.