mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[web] Fix text selection from right to left (flutter/engine#24214)
This commit is contained in:
parent
8c89d6757f
commit
aebb258346
@ -373,7 +373,11 @@ class AutofillInfo {
|
||||
/// The current text and selection state of a text field.
|
||||
@visibleForTesting
|
||||
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
|
||||
/// coming from Flutter.
|
||||
@ -401,9 +405,10 @@ class EditingState {
|
||||
final String? text = flutterEditingState['text'];
|
||||
|
||||
return EditingState(
|
||||
text: text,
|
||||
baseOffset: math.max(0, selectionBase),
|
||||
extentOffset: math.max(0, selectionExtent));
|
||||
text: text,
|
||||
baseOffset: selectionBase,
|
||||
extentOffset: selectionExtent,
|
||||
);
|
||||
}
|
||||
|
||||
/// 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', () {
|
||||
final InputElement input = document.getElementsByTagName('input')[0];
|
||||
_editingState =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user