Unverified Commit 300181b3 authored by Renzo Olivares's avatar Renzo Olivares Committed by GitHub

Make TextEditingDelta diagnosticable and override debugFillProperties for...

Make TextEditingDelta diagnosticable and override debugFillProperties for concrete TextEditingDelta implementations (#113395)
parent a707d05e
......@@ -54,7 +54,7 @@ bool _debugTextRangeIsValid(TextRange range, String text) {
/// * [TextInputConfiguration], to opt-in your [DeltaTextInputClient] to receive
/// [TextEditingDelta]'s you must set [TextInputConfiguration.enableDeltaModel]
/// to true.
abstract class TextEditingDelta {
abstract class TextEditingDelta with Diagnosticable {
/// Creates a delta for a given change to the editing state.
///
/// {@template flutter.services.TextEditingDelta}
......@@ -288,6 +288,16 @@ class TextEditingDeltaInsertion extends TextEditingDelta {
assert(_debugTextRangeIsValid(composing, newText), 'Applying TextEditingDeltaInsertion failed, the composing range: $composing is not within the bounds of $newText of length: ${newText.length}');
return value.copyWith(text: newText, selection: selection, composing: composing);
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<String>('oldText', oldText));
properties.add(DiagnosticsProperty<String>('textInserted', textInserted));
properties.add(DiagnosticsProperty<int>('insertionOffset', insertionOffset));
properties.add(DiagnosticsProperty<TextSelection>('selection', selection));
properties.add(DiagnosticsProperty<TextRange>('composing', composing));
}
}
/// A structure representing the deletion of a single/or contiguous sequence of
......@@ -324,6 +334,16 @@ class TextEditingDeltaDeletion extends TextEditingDelta {
assert(_debugTextRangeIsValid(composing, newText), 'Applying TextEditingDeltaDeletion failed, the composing range: $composing is not within the bounds of $newText of length: ${newText.length}');
return value.copyWith(text: newText, selection: selection, composing: composing);
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<String>('oldText', oldText));
properties.add(DiagnosticsProperty<String>('textDeleted', textDeleted));
properties.add(DiagnosticsProperty<TextRange>('deletedRange', deletedRange));
properties.add(DiagnosticsProperty<TextSelection>('selection', selection));
properties.add(DiagnosticsProperty<TextRange>('composing', composing));
}
}
/// A structure representing a replacement of a range of characters with a
......@@ -370,6 +390,17 @@ class TextEditingDeltaReplacement extends TextEditingDelta {
assert(_debugTextRangeIsValid(composing, newText), 'Applying TextEditingDeltaReplacement failed, the composing range: $composing is not within the bounds of $newText of length: ${newText.length}');
return value.copyWith(text: newText, selection: selection, composing: composing);
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<String>('oldText', oldText));
properties.add(DiagnosticsProperty<String>('textReplaced', textReplaced));
properties.add(DiagnosticsProperty<String>('replacementText', replacementText));
properties.add(DiagnosticsProperty<TextRange>('replacedRange', replacedRange));
properties.add(DiagnosticsProperty<TextSelection>('selection', selection));
properties.add(DiagnosticsProperty<TextRange>('composing', composing));
}
}
/// A structure representing changes to the selection and/or composing regions
......@@ -402,4 +433,12 @@ class TextEditingDeltaNonTextUpdate extends TextEditingDelta {
assert(_debugTextRangeIsValid(composing, oldText), 'Applying TextEditingDeltaNonTextUpdate failed, the composing region: $composing is not within the bounds of $oldText of length: ${oldText.length}');
return TextEditingValue(text: oldText, selection: selection, composing: composing);
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<String>('oldText', oldText));
properties.add(DiagnosticsProperty<TextSelection>('selection', selection));
properties.add(DiagnosticsProperty<TextRange>('composing', composing));
}
}
......@@ -4,6 +4,7 @@
import 'dart:convert' show jsonDecode;
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -70,6 +71,34 @@ void main() {
expect(() { delta.apply(TextEditingValue.empty); }, throwsAssertionError);
});
test('Verify TextEditingDeltaInsertion debugFillProperties', () {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
const TextEditingDeltaInsertion insertionDelta = TextEditingDeltaInsertion(
oldText: 'hello worl',
textInserted: 'd',
insertionOffset: 10,
selection: TextSelection.collapsed(offset: 11),
composing: TextRange.empty,
);
insertionDelta.debugFillProperties(builder);
final List<String> description = builder.properties
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
.map((DiagnosticsNode node) => node.toString()).toList();
expect(
description,
<String>[
'oldText: hello worl',
'textInserted: d',
'insertionOffset: 10',
'selection: TextSelection.collapsed(offset: 11, affinity: TextAffinity.downstream, isDirectional: false)',
'composing: TextRange(start: -1, end: -1)',
],
);
});
});
group('TextEditingDeltaDeletion', () {
......@@ -134,6 +163,33 @@ void main() {
expect(() { delta.apply(TextEditingValue.empty); }, throwsAssertionError);
});
test('Verify TextEditingDeltaDeletion debugFillProperties', () {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
const TextEditingDeltaDeletion deletionDelta = TextEditingDeltaDeletion(
oldText: 'hello world',
deletedRange: TextRange(start: 6, end: 10),
selection: TextSelection.collapsed(offset: 6),
composing: TextRange.empty,
);
deletionDelta.debugFillProperties(builder);
final List<String> description = builder.properties
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
.map((DiagnosticsNode node) => node.toString()).toList();
expect(
description,
<String>[
'oldText: hello world',
'textDeleted: worl',
'deletedRange: TextRange(start: 6, end: 10)',
'selection: TextSelection.collapsed(offset: 6, affinity: TextAffinity.downstream, isDirectional: false)',
'composing: TextRange(start: -1, end: -1)',
],
);
});
});
group('TextEditingDeltaReplacement', () {
......@@ -227,6 +283,35 @@ void main() {
expect(() { delta.apply(TextEditingValue.empty); }, throwsAssertionError);
});
test('Verify TextEditingDeltaReplacement debugFillProperties', () {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
const TextEditingDeltaReplacement replacementDelta = TextEditingDeltaReplacement(
oldText: 'hello world',
replacementText: 'h',
replacedRange: TextRange(start: 6, end: 11),
selection: TextSelection.collapsed(offset: 7),
composing: TextRange(start: 6, end: 7),
);
replacementDelta.debugFillProperties(builder);
final List<String> description = builder.properties
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
.map((DiagnosticsNode node) => node.toString()).toList();
expect(
description,
<String>[
'oldText: hello world',
'textReplaced: world',
'replacementText: h',
'replacedRange: TextRange(start: 6, end: 11)',
'selection: TextSelection.collapsed(offset: 7, affinity: TextAffinity.downstream, isDirectional: false)',
'composing: TextRange(start: 6, end: 7)',
],
);
});
});
group('TextEditingDeltaNonTextUpdate', () {
......@@ -262,5 +347,29 @@ void main() {
expect(() { delta.apply(TextEditingValue.empty); }, throwsAssertionError);
});
test('Verify TextEditingDeltaNonTextUpdate debugFillProperties', () {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
const TextEditingDeltaNonTextUpdate nonTextUpdateDelta = TextEditingDeltaNonTextUpdate(
oldText: 'hello world',
selection: TextSelection.collapsed(offset: 7),
composing: TextRange(start: 6, end: 7),
);
nonTextUpdateDelta.debugFillProperties(builder);
final List<String> description = builder.properties
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
.map((DiagnosticsNode node) => node.toString()).toList();
expect(
description,
<String>[
'oldText: hello world',
'selection: TextSelection.collapsed(offset: 7, affinity: TextAffinity.downstream, isDirectional: false)',
'composing: TextRange(start: 6, end: 7)',
],
);
});
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment