Bug 1068979 - Handle surrogate pair if necessary when backspacing into a text node. r=ehsan
--- a/editor/libeditor/nsHTMLEditRules.cpp
+++ b/editor/libeditor/nsHTMLEditRules.cpp
@@ -2012,23 +2012,32 @@ nsHTMLEditRules::WillDeleteSelection(Sel
else
res = wsObj.DeleteWSBackward();
*aHandled = true;
NS_ENSURE_SUCCESS(res, res);
res = InsertBRIfNeeded(aSelection);
return res;
} else if (wsType == WSType::text) {
// found normal text to delete.
+ nsRefPtr<Text> nodeAsText = visNode_->GetAsText();
int32_t so = visOffset;
int32_t eo = visOffset+1;
if (aAction == nsIEditor::ePrevious)
{
if (so == 0) return NS_ERROR_UNEXPECTED;
- so--;
- eo--;
+ so--;
+ eo--;
+ // bug 1068979: delete both codepoints if surrogate pair
+ if (so > 0) {
+ const nsTextFragment *text = nodeAsText->GetText();
+ if (NS_IS_LOW_SURROGATE(text->CharAt(so)) &&
+ NS_IS_HIGH_SURROGATE(text->CharAt(so - 1))) {
+ so--;
+ }
+ }
}
else
{
nsCOMPtr<nsIDOMRange> range;
res = aSelection->GetRangeAt(0, getter_AddRefs(range));
NS_ENSURE_SUCCESS(res, res);
#ifdef DEBUG
@@ -2048,17 +2057,16 @@ nsHTMLEditRules::WillDeleteSelection(Sel
res = range->GetEndOffset(&eo);
NS_ENSURE_SUCCESS(res, res);
}
NS_ENSURE_STATE(mHTMLEditor);
res = nsWSRunObject::PrepareToDeleteRange(mHTMLEditor,
address_of(visNode_), &so, address_of(visNode_), &eo);
NS_ENSURE_SUCCESS(res, res);
visNode = GetAsDOMNode(visNode_);
- nsRefPtr<Text> nodeAsText = visNode_->GetAsText();
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->DeleteText(*nodeAsText, std::min(so, eo),
DeprecatedAbs(eo - so));
*aHandled = true;
NS_ENSURE_SUCCESS(res, res);
res = InsertBRIfNeeded(aSelection);
return res;
} else if (wsType == WSType::special || wsType == WSType::br ||