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
--- 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 &&