Commit e2698150 authored by adele@apple.com's avatar adele@apple.com

WebCore:

2009-04-13  Adele Peterson  <adele@apple.com>

        Reviewed by Darin Adler.

        Fix for <rdar://problem/5510537> Typing return at start of block quote yields empty quoted line

        Test: editing/inserting/5510537.html

        * editing/BreakBlockquoteCommand.cpp: (WebCore::BreakBlockquoteCommand::doApply): If the break insertion position
        is at the beginning of the topmost quote, then just insert the <br> before the blockquote.  Otherwise, if the break
        insertion position is at the beginning of any quote, adjust the position so the break comes before the current quote level
        so we don't end up with an empty line in that quote in addition to the new line we're adding with the <br>.

LayoutTests:

2009-04-13  Adele Peterson  <adele@apple.com>

        Reviewed by Darin Adler.

        Test for <rdar://problem/5510537> Typing return at start of block quote yields empty quoted line

        * editing/inserting/5510537.html: Added.
        * platform/mac/editing/inserting/5510537-expected.checksum: Added.
        * platform/mac/editing/inserting/5510537-expected.png: Added.
        * platform/mac/editing/inserting/5510537-expected.txt: Added.



git-svn-id: svn://svn.chromium.org/blink/trunk@42433 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 4e8964c6
2009-04-13 Adele Peterson <adele@apple.com>
Reviewed by Darin Adler.
Test for <rdar://problem/5510537> Typing return at start of block quote yields empty quoted line
* editing/inserting/5510537.html: Added.
* platform/mac/editing/inserting/5510537-expected.checksum: Added.
* platform/mac/editing/inserting/5510537-expected.png: Added.
* platform/mac/editing/inserting/5510537-expected.txt: Added.
2009-04-12 Sam Weinig <sam@webkit.org> 2009-04-12 Sam Weinig <sam@webkit.org>
Reviewed by Mark Rowe. Reviewed by Mark Rowe.
......
<html>
<head>
<style>
blockquote {
color: blue;
border-left: 2px solid blue;
margin: 0px;
padding-left: 10px;
}
</style>
<script>
function log(msg)
{
document.getElementById('console').appendChild(document.createTextNode(msg + '\n'));
}
function test()
{
var s = window.getSelection();
s.setPosition(document.getElementById('qt'), 0);
document.execCommand("InsertNewlineInQuotedContent");
document.execCommand("InsertText", true, "unquoted");
s.setPosition(document.getElementById('qt2'), 0);
document.execCommand("InsertNewlineInQuotedContent");
document.execCommand("InsertText", true, "unquoted");
}
</script>
</head>
<body onload="test()">
<p>This tests that inserting a newline at the beginning of quoted content doesn't add an extra quoted line. The test has passed if there are no empty lines (quoted or unquoted) in the box below.</p>
<div contenteditable="true">
<blockquote type="cite"><div id="qt">quote level one</div></blockquote>
<blockquote type="cite"><div>quote level one</div><div><blockquote type="cite"><div id="qt2">quote level two</div></blockquote></div></blockquote>
</div>
<pre id="console"></pre>
</body>
</html>
8e3803b1f355fc857a3c4a6843780330
\ No newline at end of file
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x579
RenderBlock {P} at (0,0) size 784x36
RenderText {#text} at (0,0) size 773x36
text run at (0,0) width 639: "This tests that inserting a newline at the beginning of quoted content doesn't add an extra quoted line. "
text run at (639,0) width 134: "The test has passed if"
text run at (0,18) width 401: "there are no empty lines (quoted or unquoted) in the box below."
RenderBlock {DIV} at (0,52) size 784x90
RenderBlock (anonymous) at (0,0) size 784x18
RenderText {#text} at (0,0) size 59x18
text run at (0,0) width 59: "unquoted"
RenderBR {BR} at (59,14) size 0x0
RenderBlock {BLOCKQUOTE} at (0,18) size 784x18 [color=#0000FF] [border: (2px solid #0000FF)]
RenderBlock {DIV} at (12,0) size 772x18
RenderText {#text} at (0,0) size 96x18
text run at (0,0) width 96: "quote level one"
RenderBlock {BLOCKQUOTE} at (0,36) size 784x18 [color=#0000FF] [border: (2px solid #0000FF)]
RenderBlock {DIV} at (12,0) size 772x18
RenderText {#text} at (0,0) size 96x18
text run at (0,0) width 96: "quote level one"
RenderBlock (anonymous) at (0,54) size 784x18
RenderText {#text} at (0,0) size 59x18
text run at (0,0) width 59: "unquoted"
RenderBR {BR} at (59,14) size 0x0
RenderBlock {BLOCKQUOTE} at (0,72) size 784x18 [color=#0000FF] [border: (2px solid #0000FF)]
RenderBlock {DIV} at (12,0) size 772x18
RenderBlock {BLOCKQUOTE} at (0,0) size 772x18 [border: (2px solid #0000FF)]
RenderBlock {DIV} at (12,0) size 760x18
RenderText {#text} at (0,0) size 97x18
text run at (0,0) width 97: "quote level two"
RenderBlock {PRE} at (0,155) size 784x0
caret: position 8 of child 6 {#text} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
2009-04-13 Adele Peterson <adele@apple.com>
Reviewed by Darin Adler.
Fix for <rdar://problem/5510537> Typing return at start of block quote yields empty quoted line
Test: editing/inserting/5510537.html
* editing/BreakBlockquoteCommand.cpp: (WebCore::BreakBlockquoteCommand::doApply): If the break insertion position
is at the beginning of the topmost quote, then just insert the <br> before the blockquote. Otherwise, if the break
insertion position is at the beginning of any quote, adjust the position so the break comes before the current quote level
so we don't end up with an empty line in that quote in addition to the new line we're adding with the <br>.
2009-04-11 Darin Adler <darin@apple.com> 2009-04-11 Darin Adler <darin@apple.com>
Reviewed by Dan Bernstein. Reviewed by Dan Bernstein.
...@@ -56,21 +56,30 @@ void BreakBlockquoteCommand::doApply() ...@@ -56,21 +56,30 @@ void BreakBlockquoteCommand::doApply()
// be in the first node that we need to move (there are a few exceptions to this, see below). // be in the first node that we need to move (there are a few exceptions to this, see below).
Position pos = endingSelection().start().downstream(); Position pos = endingSelection().start().downstream();
// startNode is the first node that we need to move to the new blockquote.
Node* startNode = pos.node();
// Find the top-most blockquote from the start. // Find the top-most blockquote from the start.
Element* topBlockquote = 0; Element* topBlockquote = 0;
for (Node *node = startNode->parentNode(); node; node = node->parentNode()) { for (Node *node = pos.node()->parentNode(); node; node = node->parentNode()) {
if (isMailBlockquote(node)) if (isMailBlockquote(node))
topBlockquote = static_cast<Element*>(node); topBlockquote = static_cast<Element*>(node);
} }
if (!topBlockquote || !topBlockquote->parentNode()) if (!topBlockquote || !topBlockquote->parentNode())
return; return;
// Insert a break after the top blockquote.
RefPtr<Element> breakNode = createBreakElement(document()); RefPtr<Element> breakNode = createBreakElement(document());
// If the position is at the beginning of the top quoted content, we don't need to break the quote.
// Instead, insert the break before the blockquote.
if (isFirstVisiblePositionInNode(visiblePos, topBlockquote)) {
insertNodeBefore(breakNode.get(), topBlockquote);
setEndingSelection(VisibleSelection(Position(breakNode.get(), 0), DOWNSTREAM));
rebalanceWhitespace();
return;
}
// Insert a break after the top blockquote.
insertNodeAfter(breakNode.get(), topBlockquote); insertNodeAfter(breakNode.get(), topBlockquote);
// If we're inserting the break at the end of the quoted content, we don't need to break the quote.
if (isLastVisiblePositionInNode(visiblePos, topBlockquote)) { if (isLastVisiblePositionInNode(visiblePos, topBlockquote)) {
setEndingSelection(VisibleSelection(Position(breakNode.get(), 0), DOWNSTREAM)); setEndingSelection(VisibleSelection(Position(breakNode.get(), 0), DOWNSTREAM));
rebalanceWhitespace(); rebalanceWhitespace();
...@@ -82,6 +91,13 @@ void BreakBlockquoteCommand::doApply() ...@@ -82,6 +91,13 @@ void BreakBlockquoteCommand::doApply()
if (lineBreakExistsAtPosition(visiblePos)) if (lineBreakExistsAtPosition(visiblePos))
pos = pos.next(); pos = pos.next();
// Adjust the position so we don't split at the beginning of a quote.
while (isFirstVisiblePositionInNode(VisiblePosition(pos), nearestMailBlockquote(pos.node())))
pos = pos.previous();
// startNode is the first node that we need to move to the new blockquote.
Node* startNode = pos.node();
// Split at pos if in the middle of a text node. // Split at pos if in the middle of a text node.
if (startNode->isTextNode()) { if (startNode->isTextNode()) {
Text* textNode = static_cast<Text*>(startNode); Text* textNode = static_cast<Text*>(startNode);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment