forked from LadybirdBrowser/ladybird
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibWeb: Implement document.execCommand('insertLinebreak')
- Loading branch information
Showing
4 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
Tests/LibWeb/Text/expected/Editing/execCommand-insertLinebreak.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Before: "foobar" | ||
After: "foo<br>bar" | ||
Before: "<p style="white-space: pre">foobar</p>" | ||
After: "<p style="white-space: pre">foo | ||
bar</p>" | ||
Before: "<p style="white-space: pre">foobar</p>" | ||
After: "<p style="white-space: pre">foobar | ||
|
||
</p>" |
40 changes: 40 additions & 0 deletions
40
Tests/LibWeb/Text/input/Editing/execCommand-insertLinebreak.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<script src="../include.js"></script> | ||
<div id="a" contenteditable>foobar</div> | ||
<div id="b" contenteditable><p style="white-space: pre">foobar</p></div> | ||
<div id="c" contenteditable><p style="white-space: pre">foobar</p></div> | ||
<script> | ||
test(() => { | ||
let divA = document.querySelector('div#a'); | ||
let divB = document.querySelector('div#b'); | ||
let divC = document.querySelector('div#c'); | ||
|
||
document.body.offsetWidth // Force a layout | ||
|
||
// A: Insert linebreak after 'foo' | ||
println(`Before: "${divA.innerHTML}"`); | ||
var range = document.createRange(); | ||
range.setStart(divA.firstChild, 3); | ||
getSelection().addRange(range); | ||
document.execCommand('insertLinebreak'); | ||
println(`After: "${divA.innerHTML}"`); | ||
getSelection().empty(); | ||
|
||
// B: Insert linebreak after 'foo' | ||
println(`Before: "${divB.innerHTML}"`); | ||
var range = document.createRange(); | ||
range.setStart(divB.firstChild.firstChild, 3); | ||
getSelection().addRange(range); | ||
document.execCommand('insertLinebreak'); | ||
println(`After: "${divB.innerHTML}"`); | ||
getSelection().empty(); | ||
|
||
// C: Insert linebreak after 'bar' | ||
println(`Before: "${divC.innerHTML}"`); | ||
var range = document.createRange(); | ||
range.setStart(divC.firstChild.firstChild, 6); | ||
getSelection().addRange(range); | ||
document.execCommand('insertLinebreak'); | ||
println(`After: "${divC.innerHTML}"`); | ||
getSelection().empty(); | ||
}); | ||
</script> |