Fixed: <rdar://problem/3978461> smart paste is broken
authorcblu <cblu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 19 Feb 2005 18:59:07 +0000 (18:59 +0000)
committercblu <cblu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 19 Feb 2005 18:59:07 +0000 (18:59 +0000)
        Reviewed by kevin.

        * khtml/editing/htmlediting.cpp:
        (khtml::ReplaceSelectionCommand::doApply): properly check for leading and trailing whitespace. These checks were incorrectly reversed. Also check if we're pasting at the beginning or end of a line. We should not insert spaces in either case.

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

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

index 4b8982b3a3c9bc50601647349a63598c62d0dfbc..c0a63fbee6c9da7ab48807f919749896dfee9e94 100644 (file)
@@ -1,3 +1,12 @@
+2005-02-19  Chris Blumenberg  <cblu@apple.com>
+
+       Fixed: <rdar://problem/3978461> smart paste is broken
+
+        Reviewed by kevin.
+
+        * khtml/editing/htmlediting.cpp:
+        (khtml::ReplaceSelectionCommand::doApply): properly check for leading and trailing whitespace. These checks were incorrectly reversed. Also check if we're pasting at the beginning or end of a line. We should not insert spaces in either case.
+
 2005-02-18  Adele Amchan  <adele@apple.com>
 
         Reviewed by Darin.
index a0cf7db5dbdef158bea3166d68586267de04c197..9e13a98c28b0c94213200e288afc62ed03b7cbba 100644 (file)
@@ -4335,16 +4335,18 @@ void ReplaceSelectionCommand::doApply()
     // FIXME: We need the affinity for startPos and endPos, but Position::downstream
     // and Position::upstream do not give it
     if (m_smartReplace) {
-        addLeadingSpace = startPos.leadingWhitespacePosition(VP_DEFAULT_AFFINITY).isNotNull();
+        VisiblePosition visiblePos = VisiblePosition(startPos, VP_DEFAULT_AFFINITY);
+        assert(visiblePos.isNotNull());
+        addLeadingSpace = startPos.leadingWhitespacePosition(VP_DEFAULT_AFFINITY).isNull() && !isFirstVisiblePositionOnLine(visiblePos);
         if (addLeadingSpace) {
-            QChar previousChar = VisiblePosition(startPos, VP_DEFAULT_AFFINITY).previous().character();
+            QChar previousChar = visiblePos.previous().character();
             if (!previousChar.isNull()) {
                 addLeadingSpace = !part->isCharacterSmartReplaceExempt(previousChar, true);
             }
         }
-        addTrailingSpace = endPos.trailingWhitespacePosition(VP_DEFAULT_AFFINITY).isNotNull();
+        addTrailingSpace = startPos.trailingWhitespacePosition(VP_DEFAULT_AFFINITY).isNull() && !isLastVisiblePositionOnLine(visiblePos);
         if (addTrailingSpace) {
-            QChar thisChar = VisiblePosition(endPos, VP_DEFAULT_AFFINITY).character();
+            QChar thisChar = visiblePos.character();
             if (!thisChar.isNull()) {
                 addTrailingSpace = !part->isCharacterSmartReplaceExempt(thisChar, false);
             }