File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -119,13 +119,13 @@ class AttributedText {
119
119
late final String _textWithPlaceholders;
120
120
121
121
/// Returns the character or placeholder at offset zero.
122
- Object get first => placeholders[0 ] ?? _text [0 ];
122
+ Object get first => placeholders[0 ] ?? _textWithPlaceholders [0 ];
123
123
124
124
/// Returns the character or placeholder at the given [offset] .
125
- Object operator [](int offset) => placeholders[offset] ?? _text [offset];
125
+ Object operator [](int offset) => placeholders[offset] ?? _textWithPlaceholders [offset];
126
126
127
127
/// Returns the character or placeholder at the end of this `AttributedText` .
128
- Object get last => placeholders[length - 1 ] ?? _text [length - 1 ];
128
+ Object get last => placeholders[length - 1 ] ?? _textWithPlaceholders [length - 1 ];
129
129
130
130
/// Returns a plain-text version of this `AttributedText` .
131
131
///
Original file line number Diff line number Diff line change @@ -81,6 +81,26 @@ void main() {
81
81
});
82
82
});
83
83
84
+ test ("reports characters and placeholders at indices" , () {
85
+ final text1 = AttributedText ("HelloWorld" , null , {
86
+ 0 : const _FakePlaceholder ("one" ),
87
+ 6 : const _FakePlaceholder ("two" ),
88
+ 12 : const _FakePlaceholder ("three" ),
89
+ });
90
+
91
+ expect (text1.first, const _FakePlaceholder ("one" ));
92
+ expect (text1[1 ], "H" );
93
+ expect (text1[6 ], const _FakePlaceholder ("two" ));
94
+ expect (text1[11 ], "d" );
95
+ expect (text1.last, const _FakePlaceholder ("three" ));
96
+
97
+ final text2 = AttributedText ("Hello World" , null , {
98
+ 0 : const _FakePlaceholder ("one" ),
99
+ });
100
+ expect (text2[11 ], "d" );
101
+ expect (text2.last, "d" );
102
+ });
103
+
84
104
test ("reports plain text value" , () {
85
105
expect (
86
106
AttributedText ("" , null , {
You can’t perform that action at this time.
0 commit comments