[web] Fix text selection from right to left (flutter/engine#24214)
This commit is contained in:
@@ -373,7 +373,11 @@ class AutofillInfo {
|
|||||||
/// The current text and selection state of a text field.
|
/// The current text and selection state of a text field.
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
class EditingState {
|
class EditingState {
|
||||||
EditingState({this.text, this.baseOffset = 0, this.extentOffset = 0});
|
EditingState({this.text, int? baseOffset, int? extentOffset}) :
|
||||||
|
// Don't allow negative numbers. Pick the smallest selection index for base.
|
||||||
|
baseOffset = math.max(0, math.min(baseOffset ?? 0, extentOffset ?? 0)),
|
||||||
|
// Don't allow negative numbers. Pick the greatest selection index for extent.
|
||||||
|
extentOffset = math.max(0, math.max(baseOffset ?? 0, extentOffset ?? 0));
|
||||||
|
|
||||||
/// Creates an [EditingState] instance using values from an editing state Map
|
/// Creates an [EditingState] instance using values from an editing state Map
|
||||||
/// coming from Flutter.
|
/// coming from Flutter.
|
||||||
@@ -401,9 +405,10 @@ class EditingState {
|
|||||||
final String? text = flutterEditingState['text'];
|
final String? text = flutterEditingState['text'];
|
||||||
|
|
||||||
return EditingState(
|
return EditingState(
|
||||||
text: text,
|
text: text,
|
||||||
baseOffset: math.max(0, selectionBase),
|
baseOffset: selectionBase,
|
||||||
extentOffset: math.max(0, selectionExtent));
|
extentOffset: selectionExtent,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an [EditingState] instance using values from the editing element
|
/// Creates an [EditingState] instance using values from the editing element
|
||||||
|
|||||||
@@ -2095,6 +2095,24 @@ void testMain() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Fix flipped base and extent offsets', () {
|
||||||
|
expect(
|
||||||
|
EditingState(baseOffset: 10, extentOffset: 4),
|
||||||
|
EditingState(baseOffset: 4, extentOffset: 10),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
EditingState.fromFrameworkMessage(<String, dynamic>{
|
||||||
|
'selectionBase': 10,
|
||||||
|
'selectionExtent': 4,
|
||||||
|
}),
|
||||||
|
EditingState.fromFrameworkMessage(<String, dynamic>{
|
||||||
|
'selectionBase': 4,
|
||||||
|
'selectionExtent': 10,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test('Configure input element from the editing state', () {
|
test('Configure input element from the editing state', () {
|
||||||
final InputElement input = document.getElementsByTagName('input')[0];
|
final InputElement input = document.getElementsByTagName('input')[0];
|
||||||
_editingState =
|
_editingState =
|
||||||
|
|||||||
Reference in New Issue
Block a user