Reviewed by John
[WebKit-https.git] / WebCore / khtml / khtml_part.cpp
index fd70a44..3a41d31 100644 (file)
@@ -5033,6 +5033,9 @@ CSSStyleDeclarationImpl *KHTMLPart::typingStyle() const
 
 void KHTMLPart::setTypingStyle(CSSStyleDeclarationImpl *style)
 {
+    if (d->m_typingStyle == style)
+        return;
+        
     CSSStyleDeclarationImpl *old = d->m_typingStyle;
     d->m_typingStyle = style;
     if (d->m_typingStyle)
@@ -5317,13 +5320,28 @@ void KHTMLPart::applyStyle(CSSStyleDeclarationImpl *style)
             // do nothing
             break;
         case Selection::CARET: {
+            // Calculate the current typing style.
             if (typingStyle()) {
                 typingStyle()->merge(style);
                 style = typingStyle();
             }
-            CSSComputedStyleDeclarationImpl diff(selection().start().upstream(StayInBlock).node());
-            diff.diff(style);
+            style->ref();
+            CSSComputedStyleDeclarationImpl computedStyle(selection().start().upstream(StayInBlock).node());
+            computedStyle.diff(style);
+            
+            // Handle block styles, substracting these from the typing style.
+            CSSStyleDeclarationImpl *blockStyle = style->copyBlockProperties();
+            blockStyle->ref();
+            blockStyle->diff(style);
+            if (xmlDocImpl() && blockStyle->length() > 0) {
+                EditCommandPtr cmd(new ApplyStyleCommand(xmlDocImpl(), blockStyle));
+                cmd.apply();
+            }
+            blockStyle->deref();
+            
+            // Set the remaining style as the typing style.
             setTypingStyle(style);
+            style->deref();
             break;
         }
         case Selection::RANGE: