LayoutTests:
authorjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Aug 2006 20:00:37 +0000 (20:00 +0000)
committerjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Aug 2006 20:00:37 +0000 (20:00 +0000)
        Reviewed by harrison

        <rdar://problem/4700297>
        REGRESSION: After replacing a misspelled word in a sentence, the selection extends to end of current line

        Fixed:
        * editing/pasteboard/smart-paste-002-expected.checksum:
        * editing/pasteboard/smart-paste-002-expected.png:
        * editing/pasteboard/smart-paste-002-expected.txt:
        Added to demonstrate fix:
        * editing/pasteboard/4700297-expected.checksum: Added.
        * editing/pasteboard/4700297-expected.png: Added.
        * editing/pasteboard/4700297-expected.txt: Added.
        * editing/pasteboard/4700297.html: Added.
        Removed a superfluous style span:
        * editing/deleting/pruning-after-merge-1-expected.txt:
        * editing/pasteboard/interchange-newline-1-expected.txt:
        * editing/pasteboard/paste-text-019-expected.checksum:
        * editing/pasteboard/paste-text-019-expected.png:
        * editing/pasteboard/paste-text-019-expected.txt:
        * editing/selection/drag-to-contenteditable-iframe-expected.txt:
        Accidently checked in bad results yesterday:
        * editing/pasteboard/copy-paste-bidi-expected.txt:
        Equivalent render tree:
        * editing/pasteboard/smart-paste-001-expected.txt:

WebCore:

        Reviewed by harrison

        <rdar://problem/4700297>
        REGRESSION: After replacing a misspelled word in a sentence, the selection extends to end of current line

        * editing/ReplaceSelectionCommand.cpp:
        (WebCore::ReplaceSelectionCommand::doApply): Rebalance whitespace
        around insertionPos before insertion because the content might
        cause a collapse, e.g. inserting <div>foo</div> at hello^ world.
        * editing/htmlediting.cpp:
        (WebCore::rebalanceWhitespaceInTextNode): Rebalance with all nbsps
        for simplicity, we can produce sequences of regular spaces and
        nbsps on serialization (10636).

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@16122 268f45cc-cd09-0410-ab3c-d52691b4dbfc

19 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/deleting/pruning-after-merge-1-expected.txt
LayoutTests/editing/pasteboard/4700297-expected.checksum [new file with mode: 0644]
LayoutTests/editing/pasteboard/4700297-expected.png [new file with mode: 0644]
LayoutTests/editing/pasteboard/4700297-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/4700297.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/copy-paste-bidi-expected.txt
LayoutTests/editing/pasteboard/interchange-newline-1-expected.txt
LayoutTests/editing/pasteboard/paste-text-019-expected.checksum
LayoutTests/editing/pasteboard/paste-text-019-expected.png
LayoutTests/editing/pasteboard/paste-text-019-expected.txt
LayoutTests/editing/pasteboard/smart-paste-001-expected.txt
LayoutTests/editing/pasteboard/smart-paste-002-expected.checksum
LayoutTests/editing/pasteboard/smart-paste-002-expected.png
LayoutTests/editing/pasteboard/smart-paste-002-expected.txt
LayoutTests/editing/selection/drag-to-contenteditable-iframe-expected.txt
WebCore/ChangeLog
WebCore/editing/ReplaceSelectionCommand.cpp
WebCore/editing/htmlediting.cpp

index 483876b69737783456f53d83263ec0faa52025f3..412149e892b688b1c3eaa25de534a0315274bc4a 100644 (file)
@@ -1,3 +1,31 @@
+2006-08-29  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by harrison
+        
+        <rdar://problem/4700297>
+        REGRESSION: After replacing a misspelled word in a sentence, the selection extends to end of current line
+        
+        Fixed:
+        * editing/pasteboard/smart-paste-002-expected.checksum:
+        * editing/pasteboard/smart-paste-002-expected.png:
+        * editing/pasteboard/smart-paste-002-expected.txt:
+        Added to demonstrate fix:
+        * editing/pasteboard/4700297-expected.checksum: Added.
+        * editing/pasteboard/4700297-expected.png: Added.
+        * editing/pasteboard/4700297-expected.txt: Added.
+        * editing/pasteboard/4700297.html: Added.
+        Removed a superfluous style span:
+        * editing/deleting/pruning-after-merge-1-expected.txt:
+        * editing/pasteboard/interchange-newline-1-expected.txt:
+        * editing/pasteboard/paste-text-019-expected.checksum:
+        * editing/pasteboard/paste-text-019-expected.png:
+        * editing/pasteboard/paste-text-019-expected.txt:
+        * editing/selection/drag-to-contenteditable-iframe-expected.txt:
+        Accidently checked in bad results yesterday:
+        * editing/pasteboard/copy-paste-bidi-expected.txt:
+        Equivalent render tree:
+        * editing/pasteboard/smart-paste-001-expected.txt:
+
 2006-08-29  waylonis  <waylonis@google.com>
 
         Reviewed by ggaren.
index 80ed9360c4f82e69151699deca31d198201059be..58b61b866a6770f7ca4341cefebdc208d8a44bdc 100644 (file)
@@ -31,10 +31,9 @@ layer at (0,0) size 800x600
         RenderBlock (anonymous) at (0,0) size 784x18
           RenderText {#text} at (0,0) size 5x18
             text run at (0,0) width 5: "f"
-          RenderInline {SPAN} at (0,0) size 15x18
+          RenderInline {B} at (0,0) size 15x18
             RenderText {#text} at (5,0) size 15x18
               text run at (5,0) width 15: "ar"
-          RenderInline {B} at (0,0) size 0x18
         RenderBlock (anonymous) at (0,18) size 784x18
           RenderBlock {DIV} at (0,0) size 784x18
             RenderText {#text} at (0,0) size 24x18
diff --git a/LayoutTests/editing/pasteboard/4700297-expected.checksum b/LayoutTests/editing/pasteboard/4700297-expected.checksum
new file mode 100644 (file)
index 0000000..efb1ce7
--- /dev/null
@@ -0,0 +1 @@
+b3084ac0f5a3ea06f732f6663fd29ad4
\ No newline at end of file
diff --git a/LayoutTests/editing/pasteboard/4700297-expected.png b/LayoutTests/editing/pasteboard/4700297-expected.png
new file mode 100644 (file)
index 0000000..0b3f18e
Binary files /dev/null and b/LayoutTests/editing/pasteboard/4700297-expected.png differ
diff --git a/LayoutTests/editing/pasteboard/4700297-expected.txt b/LayoutTests/editing/pasteboard/4700297-expected.txt
new file mode 100644 (file)
index 0000000..649f7f9
--- /dev/null
@@ -0,0 +1,21 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 1 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 6 of #text > DIV > BODY > HTML > #document to 6 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
+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 784x584
+      RenderBlock {DIV} at (0,0) size 784x18
+        RenderText {#text} at (0,0) size 41x18
+          text run at (0,0) width 41: "There "
+        RenderText {#text} at (41,0) size 42x18
+          text run at (41,0) width 42: "should"
+        RenderText {#text} at (83,0) size 215x18
+          text run at (83,0) width 215: " be no line breaks in this sentence."
+caret: position 6 of child 1 {#text} of child 0 {DIV} of child 0 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/pasteboard/4700297.html b/LayoutTests/editing/pasteboard/4700297.html
new file mode 100644 (file)
index 0000000..e886901
--- /dev/null
@@ -0,0 +1,11 @@
+<div id="test" contenteditable="true">There&nbsp; be no line breaks in this sentence.</div>
+
+<script>
+var sel = window.getSelection();
+var e = document.getElementById("test").firstChild;
+
+sel.setPosition(e, 0);
+sel.modify("move", "forward", "word");
+sel.modify("move", "forward", "character");
+document.execCommand("InsertHTML", false, "<div>should</div>");
+</script>
\ No newline at end of file
index f647527882ac5b3e5e3073fb688636cd1a79da99..c72a823c7d52d49dd2cffeae542e4045937f07a8 100644 (file)
@@ -45,6 +45,7 @@ layer at (0,0) size 800x600
               text run at (0,0) width 32: "1234"
               text run at (32,0) width 36 RTL: "\x{5E9}\x{5D3}\x{5D2}\x{5DB}"
               text run at (68,0) width 4: ":"
+          RenderBlock (anonymous) at (0,18) size 784x0
           RenderBlock {DIV} at (0,18) size 784x18
             RenderText {#text} at (712,0) size 72x18
               text run at (712,0) width 40 RTL: "\x{5E9}\x{5D3}\x{5D2}\x{5DB}:"
index d21e2e38196840a9fb7e0e864e4fec03fda33713..547399236d7971912dea01c8e8085a04535fb58a 100644 (file)
@@ -20,9 +20,9 @@ layer at (0,0) size 800x600
         RenderBlock (anonymous) at (0,0) size 784x18
           RenderText {#text} at (0,0) size 8x18
             text run at (0,0) width 8: "x"
-          RenderText {#text} at (8,0) size 21x18
-            text run at (8,0) width 21: "foo"
-          RenderInline {SPAN} at (0,0) size 0x18
+          RenderInline {SPAN} at (0,0) size 21x18
+            RenderText {#text} at (8,0) size 21x18
+              text run at (8,0) width 21: "foo"
         RenderBlock (anonymous) at (0,18) size 784x18
           RenderBlock {DIV} at (0,0) size 784x18
             RenderText {#text} at (0,0) size 20x18
@@ -31,4 +31,4 @@ layer at (0,0) size 800x600
           RenderInline {SPAN} at (0,0) size 0x0
           RenderText {#text} at (0,0) size 8x18
             text run at (0,0) width 8: "x"
-caret: position 0 of child 3 {#text} of child 2 {DIV} of child 0 {BODY} of child 0 {HTML} of document
+caret: position 0 of child 2 {#text} of child 2 {DIV} of child 0 {BODY} of child 0 {HTML} of document
index c06614d0f287e19b80d6a51bc171461c5373294d..89e004b5d731fe7870c0a7be3565c3a4c18d078e 100644 (file)
@@ -1 +1 @@
-60a3a69108263e9487ae750e514fbcc3
\ No newline at end of file
+329f766c06e6f043242bfd9e28720822
\ No newline at end of file
index aa00f533dfd79612aa3e2ac491eccbbfa7c76ec9..85012fb37e58fff898f4cb43f16405173fa9d345 100644 (file)
Binary files a/LayoutTests/editing/pasteboard/paste-text-019-expected.png and b/LayoutTests/editing/pasteboard/paste-text-019-expected.png differ
index 62bb1af9dfe8c05e7e4f5916dcb4f5d20663d60c..49c4d3ab6e39abf1fba05648740f1caf1ef7d3c3 100644 (file)
@@ -14,7 +14,7 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: shouldInsertText:Bar replacingDOMRange:range from 4 of #text > SPAN > DIV > BODY > HTML > #document to 4 of #text > SPAN > DIV > BODY > HTML > #document givenAction:WebViewInsertActionPasted
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 4 of #text > SPAN > DIV > BODY > HTML > #document to 4 of #text > SPAN > DIV > BODY > HTML > #document toDOMRange:range from 1 of #text > DIV > BODY > HTML > #document to 1 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 4 of #text > SPAN > DIV > BODY > HTML > #document to 4 of #text > SPAN > DIV > BODY > HTML > #document toDOMRange:range from 3 of #text > SPAN > DIV > BODY > HTML > #document to 3 of #text > SPAN > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 layer at (0,0) size 800x600
@@ -67,6 +67,4 @@ layer at (0,0) size 800x600
           RenderInline {SPAN} at (0,0) size 35x28
             RenderText {#text} at (0,0) size 35x28
               text run at (0,0) width 35: "Bar"
-          RenderText {#text} at (35,0) size 6x28
-            text run at (35,0) width 6: " "
-caret: position 1 of child 2 {#text} of child 5 {DIV} of child 1 {BODY} of child 0 {HTML} of document
+caret: position 3 of child 2 {#text} of child 1 {SPAN} of child 5 {DIV} of child 1 {BODY} of child 0 {HTML} of document
index e282073503e53924d45143c191a987ddd5cdc6fe..60ade8f424ebb7f9b3d434a7e913fa5d6301462c 100644 (file)
@@ -4,7 +4,7 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 5 of #text > DIV > DIV > BODY > HTML > #document to 5 of #text > DIV > DIV > BODY > HTML > #document givenAction:WebViewInsertActionPasted
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 5 of #text > DIV > DIV > BODY > HTML > #document to 5 of #text > DIV > DIV > BODY > HTML > #document toDOMRange:range from 4 of #text > DIV > DIV > BODY > HTML > #document to 4 of #text > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 5 of #text > DIV > DIV > BODY > HTML > #document to 5 of #text > DIV > DIV > BODY > HTML > #document toDOMRange:range from 5 of #text > DIV > DIV > BODY > HTML > #document to 5 of #text > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 layer at (0,0) size 800x600
@@ -31,9 +31,9 @@ layer at (0,0) size 800x600
             text run at (0,84) width 74: "test test"
       RenderBlock {DIV} at (0,236) size 784x32
         RenderBlock {DIV} at (0,0) size 784x32 [border: (2px solid #FF0000)]
-          RenderText {#text} at (2,2) size 40x28
-            text run at (2,2) width 40: "test "
-          RenderText {#text} at (42,2) size 34x28
-            text run at (42,2) width 34: "test"
+          RenderText {#text} at (2,2) size 34x28
+            text run at (2,2) width 34: "test"
+          RenderText {#text} at (36,2) size 40x28
+            text run at (36,2) width 40: " test"
         RenderBlock (anonymous) at (0,32) size 784x0
-caret: position 4 of child 1 {#text} of child 1 {DIV} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
+caret: position 5 of child 1 {#text} of child 1 {DIV} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
index c2fe5169b1db1bffde8e0192f0115a86ce4f0f27..dff44e5e0d4fc33f3218b4d188377f03f190422a 100644 (file)
@@ -1 +1 @@
-11895ba8ba4493d17ac8a12adb18aff4
\ No newline at end of file
+2b7e6aca0cf97c095c360a8a7abc2a4d
\ No newline at end of file
index e0d14167ac26d64e6aba84749b400d5e97120339..0d94e3ef0b803a49bebb3b4ce19741f645cb3486 100644 (file)
Binary files a/LayoutTests/editing/pasteboard/smart-paste-002-expected.png and b/LayoutTests/editing/pasteboard/smart-paste-002-expected.png differ
index 47e57ad141fbda385b05e4efffd4b5fa25b34104..cc827738ace183654d84f8b48f3390fab4e10ab4 100644 (file)
@@ -4,7 +4,7 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 0 of DIV > DIV > BODY > HTML > #document to 0 of DIV > DIV > BODY > HTML > #document givenAction:WebViewInsertActionPasted
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text > DIV > DIV > BODY > HTML > #document to 1 of #text > DIV > DIV > BODY > HTML > #document toDOMRange:range from 4 of #text > DIV > DIV > BODY > HTML > #document to 4 of #text > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text > DIV > DIV > BODY > HTML > #document to 1 of #text > DIV > DIV > BODY > HTML > #document toDOMRange:range from 5 of #text > DIV > DIV > BODY > HTML > #document to 5 of #text > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 layer at (0,0) size 800x600
@@ -32,8 +32,8 @@ layer at (0,0) size 800x600
       RenderBlock {DIV} at (0,236) size 784x32
         RenderBlock (anonymous) at (0,0) size 784x0
         RenderBlock {DIV} at (0,0) size 784x32 [border: (2px solid #FF0000)]
-          RenderText {#text} at (2,2) size 34x28
-            text run at (2,2) width 34: "test"
-          RenderText {#text} at (36,2) size 40x28
-            text run at (36,2) width 40: " test"
-caret: position 4 of child 0 {#text} of child 0 {DIV} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
+          RenderText {#text} at (2,2) size 40x28
+            text run at (2,2) width 40: "test "
+          RenderText {#text} at (42,2) size 34x28
+            text run at (42,2) width 34: "test"
+caret: position 5 of child 0 {#text} of child 0 {DIV} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document
index cc0099f2d2ff1cbacacfa06b4aaffbe376c71741..6c18ed9236c58b3c4ac966c78feb8de12a12371f 100644 (file)
@@ -1,7 +1,7 @@
 EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 2 of BODY > HTML > #document to 2 of BODY > HTML > #document givenAction:WebViewInsertActionDropped
 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 2 of BODY > HTML > #document to 2 of BODY > HTML > #document toDOMRange:range from 0 of #text > BODY > HTML > #document to 5 of #text > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
-EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of BODY > HTML > #document to 6 of BODY > HTML > #document
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of BODY > HTML > #document to 4 of BODY > HTML > #document
 EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 0 of BODY > HTML > #document to 0 of BODY > HTML > #document givenAction:WebViewInsertActionDropped
index 1344fbae3a9ca2a137d74a0fb0bfd47e6c2e584b..da2997f6c66a631e628e65b49c913e715b2b37a4 100644 (file)
@@ -1,3 +1,19 @@
+2006-08-29  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by harrison
+        
+        <rdar://problem/4700297>
+        REGRESSION: After replacing a misspelled word in a sentence, the selection extends to end of current line
+
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::doApply): Rebalance whitespace
+        around insertionPos before insertion because the content might 
+        cause a collapse, e.g. inserting <div>foo</div> at hello^ world.
+        * editing/htmlediting.cpp:
+        (WebCore::rebalanceWhitespaceInTextNode): Rebalance with all nbsps
+        for simplicity, we can produce sequences of regular spaces and
+        nbsps on serialization (10636).
+
 2006-08-30  Nikolas Zimmermann  <zimmermann@kde.org>
 
         Reviewed by eseidel.
index fadc090d0c2ef63329114955fa5b791d2746fa15..9d4521f2ec2d5584e92fcb8655e8c06e96fc80c7 100644 (file)
@@ -482,6 +482,13 @@ void ReplaceSelectionCommand::doApply()
         insertionPos = endingSelection().start();
     }
     
+    // Inserting content could cause whitespace to collapse, e.g. inserting <div>foo</div> into hello^ world.
+    // We remove unrendered spaces and rebalance the rendered ones (turn them into nbsps) around insertionPos to prevent that.
+    Position upstreamInsertionPos = insertionPos.upstream();
+    deleteInsignificantText(insertionPos.upstream(), insertionPos.downstream());
+    insertionPos = upstreamInsertionPos.downstream();
+    rebalanceWhitespaceAt(insertionPos);
+    
     // NOTE: This would be an incorrect usage of downstream() if downstream() were changed to mean the last position after 
     // p that maps to the same visible position as p (since in the case where a br is at the end of a block and collapsed 
     // away, there are positions after the br which map to the same visible position as [br, 0]).  
@@ -574,7 +581,7 @@ void ReplaceSelectionCommand::doApply()
         moveParagraph(startOfParagraphToMove, endOfParagraph(startOfParagraphToMove), destination);
         m_firstNodeInserted = endingSelection().visibleStart().deepEquivalent().downstream().node();
         if (!m_lastNodeInserted->inDocument())
-            m_lastNodeInserted = endingSelection().visibleEnd().deepEquivalent().downstream().node();
+            m_lastNodeInserted = endingSelection().visibleEnd().deepEquivalent().upstream().node();
     }
             
     endOfInsertedContent = VisiblePosition(Position(m_lastNodeInserted.get(), maxDeepOffset(m_lastNodeInserted.get())));
index feac8f3b119fdcd0f6a416285011f1b05bd8301b..67a083953162f313ad6249e029ed84295606f7fa 100644 (file)
@@ -347,10 +347,8 @@ int maxDeepOffset(const Node *node)
 
 void rebalanceWhitespaceInTextNode(Node *node, unsigned int start, unsigned int length)
 {
-    static RegularExpression nonRegularWhitespace("[\xa0\n]");
-    static DeprecatedString twoSpaces("  ");
+    static RegularExpression whitespace("[ \t\n]");
     static DeprecatedString nbsp("\xa0");
-    static DeprecatedString space(" ");
      
     ASSERT(node->isTextNode());
     Text *textNode = static_cast<Text *>(node);
@@ -359,25 +357,10 @@ void rebalanceWhitespaceInTextNode(Node *node, unsigned int start, unsigned int
     
     DeprecatedString substring = text.substring(start, length).deprecatedString();
 
-    substring.replace(nonRegularWhitespace, space);
-    
-    // The sequence should alternate between spaces and nbsps, always ending in a regular space.
-    // Note: This pattern doesn't mimic TextEdit editing behavior on other clients that don't
-    // support our -webkit-nbsp-mode: space, but it comes close.
-    static DeprecatedString pattern("\xa0 ");
-    int end = length - 1; 
-    int i = substring.findRev(twoSpaces, end);
-    while (i >= 0) {
-        substring.replace(i , 2, pattern);
-        i = substring.findRev(twoSpaces, i);
-    }
-    
-    // Rendering will collapse any regular whitespace at the start or end of a line.  To prevent this, we use
-    // a nbsp at the start and end of a text node.  This is sometimes unnecessary,  E.G. <a>link</a> text
-    if (start == 0 && substring[0] == ' ')
-        substring.replace(0, 1, nbsp);
-    if (start + length == text.length() && substring[end] == ' ')
-        substring.replace(end, 1, nbsp);
+    // FIXME: We rebalance with all nbsps, for simplicity (we don't need crazy sequences while editing
+    // because all editable regions will have -webkit-nbsp-mode: space.  We should produce sequences of 
+    // regular spaces and nbsps that are better for interchange when we serialize (10636).
+    substring.replace(whitespace, nbsp);
     
     ExceptionCode ec = 0;
     textNode->deleteData(start, length, ec);