Show selection over inline code; link URLs inside code
An opaque inline-code fill painted over the selection highlight, so a selected code span looked unselected; it now keeps half the fill. Bare URLs inside inline code, fenced blocks and operator messages' backticks are now links like any other. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -46,7 +46,7 @@ Future<void> _tapText(WidgetTester tester, String text) async {
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('assistant links open through the launcher; code stays plain', (
|
||||
testWidgets('assistant links, in code too, open through the launcher', (
|
||||
tester,
|
||||
) async {
|
||||
await phoneViewport(tester);
|
||||
@@ -75,16 +75,20 @@ void main() {
|
||||
expect(_leaf(tester, text).recognizer, isA<TapGestureRecognizer>());
|
||||
}
|
||||
expect(_leaf(tester, 'this').recognizer, isNull);
|
||||
expect(_leaf(tester, 'https://example.com/inline').recognizer, isNull);
|
||||
expect(
|
||||
find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is Text &&
|
||||
widget.data == 'curl https://example.com/fenced' &&
|
||||
widget.textSpan == null,
|
||||
),
|
||||
findsOneWidget,
|
||||
_leaf(tester, 'https://example.com/inline').recognizer,
|
||||
isA<TapGestureRecognizer>(),
|
||||
);
|
||||
expect(
|
||||
_leaf(tester, 'https://example.com/fenced').recognizer,
|
||||
isA<TapGestureRecognizer>(),
|
||||
);
|
||||
expect(_leaf(tester, 'curl ').recognizer, isNull);
|
||||
final inline = spansOf(
|
||||
tester,
|
||||
'https://example.com/inline',
|
||||
).firstWhere((span) => span.style?.fontFamily != null);
|
||||
expect(inline.style?.backgroundColor, isNotNull);
|
||||
|
||||
await _tapText(tester, 'the docs');
|
||||
await _tapText(tester, 'www.example.org');
|
||||
@@ -93,6 +97,7 @@ void main() {
|
||||
expect(opened.map((uri) => '$uri'), [
|
||||
'https://example.com/docs',
|
||||
'https://www.example.org',
|
||||
'https://example.com/inline',
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -301,11 +306,8 @@ void main() {
|
||||
);
|
||||
expect(_leaf(tester, 'https://example.com/bare').recognizer, isNotNull);
|
||||
expect(
|
||||
spansOf(tester, 'https://code.com')
|
||||
.where((span) => span.text?.contains('https://code.com') ?? false)
|
||||
.single
|
||||
.recognizer,
|
||||
isNull,
|
||||
_leaf(tester, 'https://code.com').recognizer,
|
||||
isA<TapGestureRecognizer>(),
|
||||
);
|
||||
await _tapText(tester, 'https://example.com/bare');
|
||||
expect(opened.map((uri) => '$uri'), ['https://example.com/bare']);
|
||||
|
||||
@@ -52,14 +52,18 @@ void main() {
|
||||
expect(_targets('www. and www.example'), isEmpty);
|
||||
});
|
||||
|
||||
test('skips inline code and fenced code', () {
|
||||
test('finds links in inline code and fenced code too', () {
|
||||
expect(_targets('run `curl https://x.com/a` then https://y.com/b'), [
|
||||
'https://x.com/a',
|
||||
'https://y.com/b',
|
||||
]);
|
||||
expect(_targets('```\ncurl https://x.com/a\n```\nhttps://y.com/b'), [
|
||||
'https://x.com/a',
|
||||
'https://y.com/b',
|
||||
]);
|
||||
expect(_targets('```\nunclosed https://x.com'), isEmpty);
|
||||
expect(findTextLinks('`https://x.com`'), [
|
||||
const ChatTextLink(1, 14, 'https://x.com'),
|
||||
]);
|
||||
});
|
||||
|
||||
test('a markdown link in plain text links its target in place', () {
|
||||
|
||||
@@ -69,11 +69,15 @@ void main() {
|
||||
final context = tester.element(find.byType(ChatMarkdownView));
|
||||
final fill = Theme.of(context).colorScheme.surfaceContainerHighest;
|
||||
final spans = spansOf(tester, 'Use');
|
||||
final code = spans.firstWhere((span) => span.text == 'inline_code()');
|
||||
// The code's style sits on the span grouping its text (and any links).
|
||||
final code = spans.firstWhere(
|
||||
(span) => span.style != null && span.toPlainText() == 'inline_code()',
|
||||
);
|
||||
final plain = spans.firstWhere(
|
||||
(span) => span.text == ' in the middle of this sentence.',
|
||||
);
|
||||
expect(code.style?.backgroundColor, fill);
|
||||
// Half the fill, so a selection behind the code stays visible.
|
||||
expect(code.style?.backgroundColor, fill.withValues(alpha: 0.5));
|
||||
expect(plain.style?.backgroundColor, isNull);
|
||||
expect(code.style?.fontSize, isNull);
|
||||
expect(code.style?.fontFamily, appMonospaceFamily);
|
||||
|
||||
@@ -57,9 +57,10 @@ void main() {
|
||||
final inlineCode = paragraph.firstWhere(
|
||||
(span) => span.toPlainText() == 'inline',
|
||||
);
|
||||
// Half the code fill, so a selection behind it stays visible.
|
||||
expect(
|
||||
inlineCode.style?.backgroundColor,
|
||||
theme.colorScheme.surfaceContainerHighest,
|
||||
theme.colorScheme.surfaceContainerHighest.withValues(alpha: 0.5),
|
||||
);
|
||||
final plain = paragraph.firstWhere(
|
||||
(span) => span.toPlainText() == ' and snake_case_name.',
|
||||
@@ -79,7 +80,8 @@ void main() {
|
||||
final code = find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is Text &&
|
||||
widget.data == 'const answer = 42;\n keep spaces',
|
||||
widget.textSpan?.toPlainText() ==
|
||||
'const answer = 42;\n keep spaces',
|
||||
);
|
||||
expect(code, findsOneWidget);
|
||||
final scroll = find.ancestor(
|
||||
|
||||
Reference in New Issue
Block a user