Bug 1712255 - Defer SetMaxLength in SetValueFromSetRangeText r=masayuki

Capping selection range in SetValue early makes the subsequent SetSelectionRange call unable to detect actual selection range change. This patch defers it so that select events can be consistently fired.

Differential Revision: https://phabricator.services.mozilla.com/D115729
This commit is contained in:
Kagami Sascha Rosylight
2021-05-24 03:11:27 +00:00
parent 9c36f0af49
commit 55be2e6e45
6 changed files with 58 additions and 7 deletions

View File

@@ -2338,7 +2338,10 @@ void TextControlState::SetRangeText(const nsAString& aReplacement,
}
SetSelectionRange(selectionStart, selectionEnd, Optional<nsAString>(), aRv);
// The instance may have already been deleted here.
if (IsSelectionCached()) {
// SetValueFromSetRangeText skipped SetMaxLength, set it here properly
GetSelectionProperties().SetMaxLength(value.Length());
}
}
void TextControlState::DestroyEditor() {
@@ -2902,7 +2905,13 @@ bool TextControlState::SetValueWithoutTextEditor(
aHandlingSetValue.ValueSetterOptionsRef()));
SelectionProperties& props = GetSelectionProperties();
props.SetMaxLength(aHandlingSetValue.GetSettingValue().Length());
// Setting a max length and thus capping selection range early prevents
// selection change detection in setRangeText. Temporarily disable
// capping here with UINT32_MAX, and set it later in ::SetRangeText().
props.SetMaxLength(aHandlingSetValue.ValueSetterOptionsRef().contains(
ValueSetterOption::BySetRangeTextAPI)
? UINT32_MAX
: aHandlingSetValue.GetSettingValue().Length());
if (aHandlingSetValue.ValueSetterOptionsRef().contains(
ValueSetterOption::MoveCursorToEndIfValueChanged)) {
props.SetStart(aHandlingSetValue.GetSettingValue().Length());