Bug 1287655 - place textarea/input cursor at end of text when initialized; r=smaug

MozReview-Commit-ID: 2srGXFmla07
This commit is contained in:
Decky Coss
2016-07-21 14:52:49 -04:00
parent 81c40526f7
commit 14fa144b3b
21 changed files with 146 additions and 92 deletions

View File

@@ -303,9 +303,13 @@ nsTextControlFrame::EnsureEditorInitialized()
// editor.
mEditorHasBeenInitialized = true;
// Set the selection to the beginning of the text field.
nsAutoString val;
txtCtrl->GetTextEditorValue(val, true);
int32_t length = val.Length();
// Set the selection to the end of the text field. (bug 1287655)
if (weakFrame.IsAlive()) {
SetSelectionEndPoints(0, 0);
SetSelectionEndPoints(length, length);
}
}
NS_ENSURE_STATE(weakFrame.IsAlive());
@@ -426,7 +430,7 @@ nsTextControlFrame::AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
nsIContent* placeholder = txtCtrl->GetPlaceholderNode();
if (placeholder && !(aFilter & nsIContent::eSkipPlaceholderContent))
aElements.AppendElement(placeholder);
}
nscoord
@@ -927,18 +931,18 @@ nsTextControlFrame::SetSelectionStart(int32_t aSelectionStart)
nsresult rv = EnsureEditorInitialized();
NS_ENSURE_SUCCESS(rv, rv);
int32_t selStart = 0, selEnd = 0;
int32_t selStart = 0, selEnd = 0;
rv = GetSelectionRange(&selStart, &selEnd);
NS_ENSURE_SUCCESS(rv, rv);
if (aSelectionStart > selEnd) {
// Collapse to the new start point.
selEnd = aSelectionStart;
selEnd = aSelectionStart;
}
selStart = aSelectionStart;
return SetSelectionEndPoints(selStart, selEnd);
}
@@ -948,18 +952,18 @@ nsTextControlFrame::SetSelectionEnd(int32_t aSelectionEnd)
nsresult rv = EnsureEditorInitialized();
NS_ENSURE_SUCCESS(rv, rv);
int32_t selStart = 0, selEnd = 0;
int32_t selStart = 0, selEnd = 0;
rv = GetSelectionRange(&selStart, &selEnd);
NS_ENSURE_SUCCESS(rv, rv);
if (aSelectionEnd < selStart) {
// Collapse to the new end point.
selStart = aSelectionEnd;
selStart = aSelectionEnd;
}
selEnd = aSelectionEnd;
return SetSelectionEndPoints(selStart, selEnd);
}
@@ -1046,7 +1050,7 @@ nsTextControlFrame::GetSelectionRange(int32_t* aSelectionStart,
nsISelectionController* selCon = txtCtrl->GetSelectionController();
NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE);
nsCOMPtr<nsISelection> selection;
rv = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
rv = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
@@ -1185,7 +1189,7 @@ nsTextControlFrame::GetText(nsString& aText)
nsresult
nsTextControlFrame::GetPhonetic(nsAString& aPhonetic)
{
aPhonetic.Truncate(0);
aPhonetic.Truncate(0);
nsCOMPtr<nsIEditor> editor;
nsresult rv = GetEditor(getter_AddRefs(editor));