Bug 850043 - Part 1. Looking for better insertion point when using plain text editor. r?masayuki draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 17 Oct 2016 14:22:46 +0900
changeset 425809 cf6a44b9b772bdb37dc97bddeb8cf366f8370673
parent 425712 9079d167112122805f99f57bb8856e1b1675af0f
child 425810 512f527230eb8fe7219215e3b634f1b2edc3df55
push id32514
push userm_kato@ga2.so-net.ne.jp
push dateMon, 17 Oct 2016 05:34:22 +0000
reviewersmasayuki
bugs850043
milestone52.0a1
Bug 850043 - Part 1. Looking for better insertion point when using plain text editor. r?masayuki When typing character, current selection node might be anonymous DIV, not text node. So even if plain text, we might not get it. We should get text node correctly when using plain text editor. MozReview-Commit-ID: LmfYa7BqZnC
editor/libeditor/EditorBase.cpp
editor/libeditor/EditorBase.h
editor/libeditor/TextEditor.cpp
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -2267,16 +2267,25 @@ EditorBase::ScrollSelectionIntoView(bool
     selCon->ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL,
       region, nsISelectionController::SCROLL_OVERFLOW_HIDDEN);
   }
 
   return NS_OK;
 }
 
 void
+EditorBase::FindBetterInsertionPoint(nsCOMPtr<nsIDOMNode>& aNode,
+                                     int32_t& aOffset)
+{
+  nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
+  FindBetterInsertionPoint(node, aOffset);
+  aNode = do_QueryInterface(node);
+}
+
+void
 EditorBase::FindBetterInsertionPoint(nsCOMPtr<nsINode>& aNode,
                                      int32_t& aOffset)
 {
   if (aNode->IsNodeOfType(nsINode::eTEXT)) {
     // There is no "better" insertion point.
     return;
   }
 
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -917,16 +917,18 @@ public:
    * the aTextNode.  If there is no IME selection, returns -1.
    */
   int32_t GetIMESelectionStartOffsetIn(nsINode* aTextNode);
 
   /**
    * FindBetterInsertionPoint() tries to look for better insertion point which
    * is typically the nearest text node and offset in it.
    */
+  void FindBetterInsertionPoint(nsCOMPtr<nsIDOMNode>& aNode,
+                                int32_t& aOffset);
   void FindBetterInsertionPoint(nsCOMPtr<nsINode>& aNode,
                                 int32_t& aOffset);
 
   /**
    * HideCaret() hides caret with nsCaret::AddForceHide() or may show carent
    * with nsCaret::RemoveForceHide().  This does NOT set visibility of
    * nsCaret.  Therefore, this is stateless.
    */
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -611,16 +611,19 @@ TextEditor::ExtendSelectionForDelete(Sel
         // to make sure that pressing backspace will only delete the last
         // typed character.
         nsCOMPtr<nsIDOMNode> node;
         int32_t offset;
         result = GetStartNodeAndOffset(aSelection, getter_AddRefs(node), &offset);
         NS_ENSURE_SUCCESS(result, result);
         NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
 
+        // node might be anonymous DIV, so we find better text node
+        FindBetterInsertionPoint(node, offset);
+
         if (IsTextNode(node)) {
           nsCOMPtr<nsIDOMCharacterData> charData = do_QueryInterface(node);
           if (charData) {
             nsAutoString data;
             result = charData->GetData(data);
             NS_ENSURE_SUCCESS(result, result);
 
             if ((offset > 1 &&