Reviewed by Chris
authorkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 May 2004 20:29:56 +0000 (20:29 +0000)
committerkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 May 2004 20:29:56 +0000 (20:29 +0000)
        Defer setting the selection to delete when none has been passed in to the
        time that the command is run. This fixes a problem where a command nested
        in a composite was not correctly picking up the right selection to begin
        its work. Now, the command will correctly use the ending selection of
        its parent when no selection has been passed in.

        * khtml/editing/htmlediting_impl.cpp:
        (khtml::DeleteCollapsibleWhitespaceCommandImpl::DeleteCollapsibleWhitespaceCommandImpl):
        (khtml::DeleteCollapsibleWhitespaceCommandImpl::doApply):
        (khtml::DeleteSelectionCommandImpl::DeleteSelectionCommandImpl):
        (khtml::DeleteSelectionCommandImpl::doApply):
        * khtml/editing/htmlediting_impl.h:

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

WebCore/ChangeLog-2005-08-23
WebCore/khtml/editing/htmlediting_impl.cpp
WebCore/khtml/editing/htmlediting_impl.h

index 1b2a517..4935d6c 100644 (file)
@@ -1,3 +1,20 @@
+2004-05-25  Ken Kocienda  <kocienda@apple.com>
+
+        Reviewed by Chris
+        
+        Defer setting the selection to delete when none has been passed in to the
+        time that the command is run. This fixes a problem where a command nested
+        in a composite was not correctly picking up the right selection to begin
+        its work. Now, the command will correctly use the ending selection of
+        its parent when no selection has been passed in.
+
+        * khtml/editing/htmlediting_impl.cpp:
+        (khtml::DeleteCollapsibleWhitespaceCommandImpl::DeleteCollapsibleWhitespaceCommandImpl):
+        (khtml::DeleteCollapsibleWhitespaceCommandImpl::doApply):
+        (khtml::DeleteSelectionCommandImpl::DeleteSelectionCommandImpl):
+        (khtml::DeleteSelectionCommandImpl::doApply):
+        * khtml/editing/htmlediting_impl.h:
+
 2004-05-24  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Dave.
index 2d128ff..5683ba8 100644 (file)
@@ -1047,12 +1047,12 @@ void ApplyStyleCommandImpl::applyUsingFragment()
 // DeleteCollapsibleWhitespaceCommandImpl
 
 DeleteCollapsibleWhitespaceCommandImpl::DeleteCollapsibleWhitespaceCommandImpl(DocumentImpl *document)
-    : CompositeEditCommandImpl(document), m_selectionToCollapse(endingSelection()), m_charactersDeleted(0)
+    : CompositeEditCommandImpl(document), m_charactersDeleted(0), m_hasSelectionToCollapse(false)
 {
 }
 
 DeleteCollapsibleWhitespaceCommandImpl::DeleteCollapsibleWhitespaceCommandImpl(DocumentImpl *document, const Selection &selection)
-    : CompositeEditCommandImpl(document), m_selectionToCollapse(selection), m_charactersDeleted(0)
+    : CompositeEditCommandImpl(document), m_charactersDeleted(0), m_selectionToCollapse(selection), m_hasSelectionToCollapse(true)
 {
 }
 
@@ -1178,6 +1178,10 @@ Position DeleteCollapsibleWhitespaceCommandImpl::deleteWhitespace(const Position
 
 void DeleteCollapsibleWhitespaceCommandImpl::doApply()
 {
+    // If selection has not been set to a custom selection when the command was created,
+    // use the current ending selection.
+    if (!m_hasSelectionToCollapse)
+        m_selectionToCollapse = endingSelection();
     int state = m_selectionToCollapse.state();
     if (state == Selection::CARET) {
         Position endPosition = deleteWhitespace(m_selectionToCollapse.start());
@@ -1202,15 +1206,13 @@ void DeleteCollapsibleWhitespaceCommandImpl::doApply()
 // DeleteSelectionCommandImpl
 
 DeleteSelectionCommandImpl::DeleteSelectionCommandImpl(DocumentImpl *document)
-    : CompositeEditCommandImpl(document)
+    : CompositeEditCommandImpl(document), m_hasSelectionToDelete(false)
 {
-    m_selectionToDelete = endingSelection();
 }
 
 DeleteSelectionCommandImpl::DeleteSelectionCommandImpl(DocumentImpl *document, const Selection &selection)
-    : CompositeEditCommandImpl(document)
+    : CompositeEditCommandImpl(document), m_selectionToDelete(selection), m_hasSelectionToDelete(true)
 {
-    m_selectionToDelete = selection;
 }
 
 DeleteSelectionCommandImpl::~DeleteSelectionCommandImpl()
@@ -1289,6 +1291,11 @@ bool DeleteSelectionCommandImpl::containsOnlyWhitespace(const Position &start, c
 
 void DeleteSelectionCommandImpl::doApply()
 {
+    // If selection has not been set to a custom selection when the command was created,
+    // use the current ending selection.
+    if (!m_hasSelectionToDelete)
+        m_selectionToDelete = endingSelection();
+        
     if (m_selectionToDelete.state() != Selection::RANGE)
         return;
 
index f33ae3c..b737416 100644 (file)
@@ -237,8 +237,9 @@ public:
 private:
     DOM::Position deleteWhitespace(const DOM::Position &pos);
 
-    DOM::Selection m_selectionToCollapse;
     unsigned long m_charactersDeleted;
+    DOM::Selection m_selectionToCollapse;
+    bool m_hasSelectionToCollapse;
 };
 
 //------------------------------------------------------------------------------------------
@@ -262,6 +263,7 @@ private:
     void joinTextNodesWithSameStyle();
 
     DOM::Selection m_selectionToDelete;
+    bool m_hasSelectionToDelete;
 };
 
 //------------------------------------------------------------------------------------------