Fixed: <rdar://problem/4029934> smart paste with plain text can add too many spaces
authorcblu <cblu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Mar 2005 19:16:45 +0000 (19:16 +0000)
committercblu <cblu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Mar 2005 19:16:45 +0000 (19:16 +0000)
        Reviewed by kocienda.

        * khtml/editing/htmlediting.cpp:
        (khtml::ReplaceSelectionCommand::doApply): pass true for treatNBSPAsWhitespace to leadingWhitespacePosition and trailingWhitespacePosition
        * khtml/xml/dom_position.cpp:
        (DOM::isWS): take treatNBSPAsWhitespace param
        (DOM::Position::leadingWhitespacePosition): ditto
        (DOM::Position::trailingWhitespacePosition): ditto
        * khtml/xml/dom_position.h:

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

WebCore/ChangeLog-2005-08-23
WebCore/khtml/editing/htmlediting.cpp
WebCore/khtml/xml/dom_position.cpp
WebCore/khtml/xml/dom_position.h

index d70ff86838003e42c7ad8138b1bca7d8aff33996..a987e3bf45c5ea958a63e8d0186c964a09933bc5 100644 (file)
@@ -1,3 +1,17 @@
+2005-03-01  Chris Blumenberg  <cblu@apple.com>
+
+       Fixed: <rdar://problem/4029934> smart paste with plain text can add too many spaces
+
+        Reviewed by kocienda.
+
+        * khtml/editing/htmlediting.cpp:
+        (khtml::ReplaceSelectionCommand::doApply): pass true for treatNBSPAsWhitespace to leadingWhitespacePosition and trailingWhitespacePosition
+        * khtml/xml/dom_position.cpp:
+        (DOM::isWS): take treatNBSPAsWhitespace param
+        (DOM::Position::leadingWhitespacePosition): ditto
+        (DOM::Position::trailingWhitespacePosition): ditto
+        * khtml/xml/dom_position.h:
+
 2005-03-01  Ken Kocienda  <kocienda@apple.com>
 
         Reviewed by John
index c672a8de23b6afd3a5ae7d87674b617e7407f1ec..207b16aedd0d1002246cb3b6f165617cc6bb85d3 100644 (file)
@@ -4539,14 +4539,14 @@ void ReplaceSelectionCommand::doApply()
     if (m_smartReplace) {
         VisiblePosition visiblePos = VisiblePosition(startPos, VP_DEFAULT_AFFINITY);
         assert(visiblePos.isNotNull());
-        addLeadingSpace = startPos.leadingWhitespacePosition(VP_DEFAULT_AFFINITY).isNull() && !isFirstVisiblePositionOnLine(visiblePos);
+        addLeadingSpace = startPos.leadingWhitespacePosition(VP_DEFAULT_AFFINITY, true).isNull() && !isFirstVisiblePositionOnLine(visiblePos);
         if (addLeadingSpace) {
             QChar previousChar = visiblePos.previous().character();
             if (!previousChar.isNull()) {
                 addLeadingSpace = !part->isCharacterSmartReplaceExempt(previousChar, true);
             }
         }
-        addTrailingSpace = startPos.trailingWhitespacePosition(VP_DEFAULT_AFFINITY).isNull() && !isLastVisiblePositionOnLine(visiblePos);
+        addTrailingSpace = startPos.trailingWhitespacePosition(VP_DEFAULT_AFFINITY, true).isNull() && !isLastVisiblePositionOnLine(visiblePos);
         if (addTrailingSpace) {
             QChar thisChar = visiblePos.character();
             if (!thisChar.isNull()) {
index 4495c00ea546e64dcf5c65eea94a5a7a884ee066..074b5423d7f32d0d86f5b915efc65128d4836cb9 100644 (file)
@@ -609,13 +609,13 @@ bool Position::rendersInDifferentPosition(const Position &pos) const
     return true;
 }
 
-static inline bool isWS(const QChar &c)
+static inline bool isWS(const QChar &c, bool treatNBSPAsWhiteSpace)
 {
     const char nonBreakingSpace = 0xA0;
-    return c.isSpace() && c != nonBreakingSpace;
+    return (c.isSpace() && c != nonBreakingSpace) || (treatNBSPAsWhiteSpace && c == nonBreakingSpace);
 }
 
-Position Position::leadingWhitespacePosition(EAffinity affinity) const
+Position Position::leadingWhitespacePosition(EAffinity affinity, bool treatNBSPAsWhiteSpace) const
 {
     if (isNull())
         return Position();
@@ -626,14 +626,14 @@ Position Position::leadingWhitespacePosition(EAffinity affinity) const
     Position prev = previousCharacterPosition(affinity);
     if (prev != *this && prev.node()->inSameContainingBlockFlowElement(node()) && prev.node()->isTextNode()) {
         DOMString string = static_cast<TextImpl *>(prev.node())->data();
-        if (isWS(string[prev.offset()]))
+        if (isWS(string[prev.offset()], treatNBSPAsWhiteSpace))
             return prev;
     }
 
     return Position();
 }
 
-Position Position::trailingWhitespacePosition(EAffinity affinity) const
+Position Position::trailingWhitespacePosition(EAffinity affinity, bool treatNBSPAsWhiteSpace) const
 {
     if (isNull())
         return Position();
@@ -642,7 +642,7 @@ Position Position::trailingWhitespacePosition(EAffinity affinity) const
         TextImpl *textNode = static_cast<TextImpl *>(node());
         if (offset() < (long)textNode->length()) {
             DOMString string = static_cast<TextImpl *>(node())->data();
-            if (isWS(string[offset()]))
+            if (isWS(string[offset()], treatNBSPAsWhiteSpace))
                 return *this;
             return Position();
         }
@@ -654,7 +654,7 @@ Position Position::trailingWhitespacePosition(EAffinity affinity) const
     Position next = nextCharacterPosition(affinity);
     if (next != *this && next.node()->inSameContainingBlockFlowElement(node()) && next.node()->isTextNode()) {
         DOMString string = static_cast<TextImpl *>(next.node())->data();
-        if (isWS(string[0]))
+        if (isWS(string[0], treatNBSPAsWhiteSpace))
             return next;
     }
 
index a46fefcb02417084199e926dd1530e05e0760baf..e2404c78553cb20a7475fe3e75eb337db6c04102 100644 (file)
@@ -59,8 +59,8 @@ public:
     ElementImpl *element() const;
     CSSComputedStyleDeclarationImpl *computedStyle() const;
 
-    Position leadingWhitespacePosition(khtml::EAffinity affinity) const;
-    Position trailingWhitespacePosition(khtml::EAffinity affinity) const;
+    Position leadingWhitespacePosition(khtml::EAffinity affinity, bool treatNBSPAsWhiteSpace=false) const;
+    Position trailingWhitespacePosition(khtml::EAffinity affinity, bool treatNBSPAsWhiteSpace=false) const;
 
     // These functions only consider leaf nodes, and if stayInBlock is true, blocks.
     // Hence, the results from these functions are idiosyncratic, and until you