Fixed: <rdar://problem/3838413> REGRESSION (Mail): "Smart" word paste adds spaces...
authorcblu <cblu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 6 Nov 2004 00:36:52 +0000 (00:36 +0000)
committercblu <cblu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 6 Nov 2004 00:36:52 +0000 (00:36 +0000)
        Reviewed by rjw.

        * khtml/editing/htmlediting.cpp:
        (khtml::ReplaceSelectionCommand::doApply): call isCharacterSmartReplaceExempt on the part to see if a space should be inserted
        * khtml/editing/visible_position.cpp:
        (khtml::VisiblePosition::character): new, returns the character for the position
        * khtml/editing/visible_position.h:
        * kwq/KWQKHTMLPart.h:
        * kwq/KWQKHTMLPart.mm:
        (KWQKHTMLPart::isCharacterSmartReplaceExempt): new, calls the bridge
        * kwq/WebCoreBridge.h:

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

WebCore/ChangeLog-2005-08-23
WebCore/khtml/editing/htmlediting.cpp
WebCore/khtml/editing/visible_position.cpp
WebCore/khtml/editing/visible_position.h
WebCore/kwq/KWQKHTMLPart.h
WebCore/kwq/KWQKHTMLPart.mm
WebCore/kwq/WebCoreBridge.h

index 3bb71ebb9fba4df9cd3fa286f0938375d9bf969e..8efa72183ec36dca440a8450abc77f16c54f9983 100644 (file)
@@ -1,3 +1,19 @@
+2004-11-05  Chris Blumenberg  <cblu@apple.com>
+
+       Fixed: <rdar://problem/3838413> REGRESSION (Mail): "Smart" word paste adds spaces before/after special characters
+
+        Reviewed by rjw.
+
+        * khtml/editing/htmlediting.cpp:
+        (khtml::ReplaceSelectionCommand::doApply): call isCharacterSmartReplaceExempt on the part to see if a space should be inserted
+        * khtml/editing/visible_position.cpp:
+        (khtml::VisiblePosition::character): new, returns the character for the position
+        * khtml/editing/visible_position.h:
+        * kwq/KWQKHTMLPart.h:
+        * kwq/KWQKHTMLPart.mm:
+        (KWQKHTMLPart::isCharacterSmartReplaceExempt): new, calls the bridge
+        * kwq/WebCoreBridge.h:
+
 === Safari-170 ===
 
 2004-11-05  Adele Amchan  <adele@apple.com>
index 5d0a045875ab68ae791d6a93e8de2d1c4c5830e3..84a12932af9a897987f206c60cc1b232fc5ab734 100644 (file)
@@ -2587,11 +2587,14 @@ void ReplaceSelectionCommand::doApply()
     if (selection.isRange())
         deleteSelection();
     
+    KHTMLPart *part = document()->part();
+    ASSERT(part);
+    
     // This command does not use any typing style that is set as a residual effect of
     // a delete.
     // FIXME: Improve typing style.
     // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
-    document()->part()->clearTypingStyle();
+    part->clearTypingStyle();
     setTypingStyle(0);
     
     selection = endingSelection();
@@ -2611,6 +2614,21 @@ void ReplaceSelectionCommand::doApply()
         addLeadingSpace = pos.leadingWhitespacePosition().isNull();
         addTrailingSpace = pos.trailingWhitespacePosition().isNull();
     }
+
+#if APPLE_CHANGES
+    if (addLeadingSpace) {
+        QChar previousChar = VisiblePosition(pos).previous().character();
+        if (!previousChar.isNull()) {
+            addLeadingSpace = !KWQ(part)->isCharacterSmartReplaceExempt(previousChar, true);
+        }
+    }
+    if (addTrailingSpace) {
+        QChar thisChar = VisiblePosition(pos).character();
+        if (!thisChar.isNull()) {
+            addTrailingSpace = !KWQ(part)->isCharacterSmartReplaceExempt(thisChar, false);
+        }
+    }
+#endif
     
     if (!firstChild) {
         // Pasting something that didn't parse or was empty.
index 7bb8971f0ceccd9d696d7feebf665ad07b603665..5f9225467c23a95e3872fd340fdd5425e9ecd08b 100644 (file)
@@ -28,6 +28,7 @@
 #include "misc/htmltags.h"
 #include "rendering/render_text.h"
 #include "xml/dom2_rangeimpl.h"
+#include "xml/dom_textimpl.h"
 
 #if APPLE_CHANGES
 #include "KWQAssertions.h"
@@ -43,6 +44,7 @@ using DOM::Position;
 using DOM::Range;
 using DOM::RangeImpl;
 using DOM::StayInBlock;
+using DOM::TextImpl;
 
 namespace khtml {
 
@@ -389,6 +391,21 @@ bool VisiblePosition::isAtomicNode(const NodeImpl *node)
     return node && (!node->hasChildNodes() || (node->id() == ID_OBJECT && node->renderer() && node->renderer()->isReplaced()));
 }
 
+QChar VisiblePosition::character() const
+{
+    Position pos = position();
+    NodeImpl *node = pos.node();
+    if (!node || !node->isTextNode()) {
+        return QChar();
+    }
+    TextImpl *textNode = static_cast<TextImpl *>(pos.node());
+    long offset = pos.offset();
+    if ((unsigned)offset >= textNode->length()) {
+        return QChar();
+    }
+    return textNode->data()[offset];
+}
+
 void VisiblePosition::debugPosition(const char *msg) const
 {
     if (isNull())
index b5e36ae46206565572d6851c573990e5c6bdc587..b6e05a78b0e43d4d0d82d690678992e28572159b 100644 (file)
@@ -26,6 +26,8 @@
 #ifndef KHTML_EDITING_VISIBLE_POSITION_H
 #define KHTML_EDITING_VISIBLE_POSITION_H
 
+#include <qstring.h>
+
 #include "xml/dom_position.h"
 #include "text_affinity.h"
 
@@ -63,6 +65,8 @@ public:
 
     bool isLastInBlock() const;
 
+    QChar character() const;
+    
     void debugPosition(const char *msg = "") const;
 
 #ifndef NDEBUG
index 57da465194e10d8ab2805feacefeda9ddbc20d15..04b47348ebdd654e649f74456862662c63ca0d95 100644 (file)
@@ -359,6 +359,8 @@ public:
     NSMutableDictionary *dashboardRegionsDictionary();
     void dashboardRegionsChanged();
     
+    bool isCharacterSmartReplaceExempt(const QChar &, bool);
+    
 private:
     virtual void khtmlMousePressEvent(khtml::MousePressEvent *);
     virtual void khtmlMouseDoubleClickEvent(khtml::MouseDoubleClickEvent *);
index 50401f9b8a4980917e1e012827a9965542c3f2cf..4e1c491287aa74b7d1c37b6d52b040da984f5a82 100644 (file)
@@ -4185,3 +4185,8 @@ void KWQKHTMLPart::dashboardRegionsChanged()
     NSMutableDictionary *webRegions = dashboardRegionsDictionary();
     [_bridge dashboardRegionsChanged:webRegions];
 }
+
+bool KWQKHTMLPart::isCharacterSmartReplaceExempt(const QChar &c, bool isPreviousChar)
+{
+    return [_bridge isCharacterSmartReplaceExempt:c.unicode() isPreviousCharacter:isPreviousChar];
+}
index 29ba7290ce2172a5ed6099fc01e68c555310d699..4a1e0187f128e935e3b463f861d9f490e072d9d6 100644 (file)
@@ -544,6 +544,8 @@ typedef enum {
 
 - (void)dashboardRegionsChanged:(NSMutableDictionary *)regions;
 
+- (BOOL)isCharacterSmartReplaceExempt:(unichar)c isPreviousCharacter:(BOOL)isPreviousCharacter;
+
 @end
 
 // This interface definition allows those who hold a WebCoreBridge * to call all the methods