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 {
119119 late final String _textWithPlaceholders;
120120
121121 /// Returns the character or placeholder at offset zero.
122- Object get first => placeholders[0 ] ?? _text [0 ];
122+ Object get first => placeholders[0 ] ?? _textWithPlaceholders [0 ];
123123
124124 /// 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];
126126
127127 /// 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 ];
129129
130130 /// Returns a plain-text version of this `AttributedText` .
131131 ///
Original file line number Diff line number Diff line change @@ -81,6 +81,26 @@ void main() {
8181 });
8282 });
8383
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+
84104 test ("reports plain text value" , () {
85105 expect (
86106 AttributedText ("" , null , {
You can’t perform that action at this time.
0 commit comments