nsresult TextEditRules::HideLastPWInput() { if (!mLastLength) { // Special case, we're trying to replace a range that no longer exists return NS_OK; } nsAutoString hiddenText; FillBufWithPWChars(&hiddenText, mLastLength); NS_ENSURE_STATE(mTextEditor); RefPtr<Selection> selection = mTextEditor->GetSelection(); NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER); uint32_t start, end; nsContentUtils::GetSelectionInTextControl(selection, mTextEditor->GetRoot(), start, end); nsCOMPtr<nsINode> selNode = GetTextNode(selection); NS_ENSURE_TRUE(selNode, NS_OK); selNode->GetAsText()->ReplaceData(mLastStart, mLastLength, hiddenText); // XXXbz Selection::Collapse/Extend take int32_t, but there are tons of // callsites... Converting all that is a battle for another day. selection->Collapse(selNode, start); if (start != end) { selection->Extend(selNode, end); } return NS_OK; }
nsresult nsTextEditRules::HideLastPWInput() { if (!mLastLength) { // Special case, we're trying to replace a range that no longer exists return NS_OK; } nsAutoString hiddenText; FillBufWithPWChars(&hiddenText, mLastLength); nsCOMPtr<nsISelection> selection; PRUint32 start, end; nsresult res = mEditor->GetSelection(getter_AddRefs(selection)); NS_ENSURE_SUCCESS(res, res); res = mEditor->GetTextSelectionOffsets(selection, start, end); NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> selNode = GetTextNode(selection, mEditor); NS_ENSURE_TRUE(selNode, NS_OK); nsCOMPtr<nsIDOMCharacterData> nodeAsText(do_QueryInterface(selNode)); NS_ENSURE_TRUE(nodeAsText, NS_OK); nodeAsText->ReplaceData(mLastStart, mLastLength, hiddenText); selection->Collapse(selNode, start); if (start != end) selection->Extend(selNode, end); return NS_OK; }