@@ -70,15 +70,27 @@ class MessageTokenText extends StatelessWidget {
70
70
}
71
71
72
72
class TokenPosition {
73
+ /// Start index of the full substring in the message
73
74
final int start;
75
+
76
+ /// End index of the full substring in the message
74
77
final int end;
78
+
79
+ /// Start index of the token in the message
80
+ final int tokenStart;
81
+
82
+ /// End index of the token in the message
83
+ final int tokenEnd;
84
+
75
85
final bool selected;
76
86
final bool hideContent;
77
87
final PangeaToken ? token;
78
88
79
89
const TokenPosition ({
80
90
required this .start,
81
91
required this .end,
92
+ required this .tokenStart,
93
+ required this .tokenEnd,
82
94
required this .hideContent,
83
95
required this .selected,
84
96
this .token,
@@ -225,6 +237,19 @@ class MessageTextWidget extends StatelessWidget {
225
237
),
226
238
);
227
239
}
240
+
241
+ // if the tokenPosition is a combination of the token and following punctuation
242
+ // split them so that only the token itself is highlighted when clicked
243
+ String firstSubstring = substring;
244
+ String secondSubstring = '' ;
245
+
246
+ if (tokenPosition.end != tokenPosition.tokenEnd) {
247
+ final splitIndex = (tokenPosition.end - tokenPosition.start) -
248
+ (tokenPosition.end - tokenPosition.tokenEnd);
249
+ firstSubstring = substring.substring (0 , splitIndex);
250
+ secondSubstring = substring.substring (splitIndex);
251
+ }
252
+
228
253
return WidgetSpan (
229
254
child: MouseRegion (
230
255
cursor: SystemMouseCursors .click,
@@ -233,21 +258,40 @@ class MessageTextWidget extends StatelessWidget {
233
258
? () => onClick? .call (tokenPosition)
234
259
: null ,
235
260
child: RichText (
236
- text: LinkifySpan (
237
- text: substring,
238
- style: style.merge (
239
- TextStyle (
240
- backgroundColor: backgroundColor,
261
+ text: TextSpan (
262
+ children: [
263
+ LinkifySpan (
264
+ text: firstSubstring,
265
+ style: style.merge (
266
+ TextStyle (
267
+ backgroundColor: backgroundColor,
268
+ ),
269
+ ),
270
+ linkStyle: TextStyle (
271
+ decoration: TextDecoration .underline,
272
+ color:
273
+ Theme .of (context).brightness == Brightness .light
274
+ ? Theme .of (context).colorScheme.primary
275
+ : Theme .of (context).colorScheme.onPrimary,
276
+ ),
277
+ onOpen: (url) =>
278
+ UrlLauncher (context, url.url).launchUrl (),
241
279
),
242
- ),
243
- linkStyle: TextStyle (
244
- decoration: TextDecoration .underline,
245
- color: Theme .of (context).brightness == Brightness .light
246
- ? Theme .of (context).colorScheme.primary
247
- : Theme .of (context).colorScheme.onPrimary,
248
- ),
249
- onOpen: (url) =>
250
- UrlLauncher (context, url.url).launchUrl (),
280
+ if (secondSubstring.isNotEmpty)
281
+ LinkifySpan (
282
+ text: secondSubstring,
283
+ style: style,
284
+ linkStyle: TextStyle (
285
+ decoration: TextDecoration .underline,
286
+ color: Theme .of (context).brightness ==
287
+ Brightness .light
288
+ ? Theme .of (context).colorScheme.primary
289
+ : Theme .of (context).colorScheme.onPrimary,
290
+ ),
291
+ onOpen: (url) =>
292
+ UrlLauncher (context, url.url).launchUrl (),
293
+ ),
294
+ ],
251
295
),
252
296
),
253
297
),
0 commit comments