@@ -238,16 +238,24 @@ class MessageTextWidget extends StatelessWidget {
238
238
);
239
239
}
240
240
241
- // if the tokenPosition is a combination of the token and following punctuation
241
+ // if the tokenPosition is a combination of the token and preceding / following punctuation
242
242
// split them so that only the token itself is highlighted when clicked
243
- String firstSubstring = substring;
244
- String secondSubstring = '' ;
243
+ String start = '' ;
244
+ String middle = substring;
245
+ String end = '' ;
246
+
247
+ if (tokenPosition.tokenStart != tokenPosition.start) {
248
+ final splitIndex =
249
+ (tokenPosition.tokenStart - tokenPosition.start);
250
+ start = substring.substring (0 , splitIndex);
251
+ middle = substring.substring (splitIndex);
252
+ }
245
253
246
254
if (tokenPosition.end != tokenPosition.tokenEnd) {
247
255
final splitIndex = (tokenPosition.end - tokenPosition.start) -
248
256
(tokenPosition.end - tokenPosition.tokenEnd);
249
- firstSubstring = substring .substring (0 , splitIndex);
250
- secondSubstring = substring.substring (splitIndex);
257
+ middle = middle .substring (0 , splitIndex);
258
+ end = substring.substring (splitIndex);
251
259
}
252
260
253
261
return WidgetSpan (
@@ -260,8 +268,22 @@ class MessageTextWidget extends StatelessWidget {
260
268
child: RichText (
261
269
text: TextSpan (
262
270
children: [
271
+ if (start.isNotEmpty)
272
+ LinkifySpan (
273
+ text: start,
274
+ style: style,
275
+ linkStyle: TextStyle (
276
+ decoration: TextDecoration .underline,
277
+ color: Theme .of (context).brightness ==
278
+ Brightness .light
279
+ ? Theme .of (context).colorScheme.primary
280
+ : Theme .of (context).colorScheme.onPrimary,
281
+ ),
282
+ onOpen: (url) =>
283
+ UrlLauncher (context, url.url).launchUrl (),
284
+ ),
263
285
LinkifySpan (
264
- text: firstSubstring ,
286
+ text: middle ,
265
287
style: style.merge (
266
288
TextStyle (
267
289
backgroundColor: backgroundColor,
@@ -277,9 +299,9 @@ class MessageTextWidget extends StatelessWidget {
277
299
onOpen: (url) =>
278
300
UrlLauncher (context, url.url).launchUrl (),
279
301
),
280
- if (secondSubstring .isNotEmpty)
302
+ if (end .isNotEmpty)
281
303
LinkifySpan (
282
- text: secondSubstring ,
304
+ text: end ,
283
305
style: style,
284
306
linkStyle: TextStyle (
285
307
decoration: TextDecoration .underline,
0 commit comments