-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changed linkification on paste to match URL parsing within the linkification reaction (Resolves #2031) #2045
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:flutter_test_robots/flutter_test_robots.dart'; | ||
|
@@ -9,7 +10,7 @@ import '../supereditor_test_tools.dart'; | |
|
||
void main() { | ||
group('SuperEditor link editing >', () { | ||
group('recognizes a URL and converts it to a link', () { | ||
group('recognizes a URL with https and www and converts it to a link', () { | ||
testWidgetsOnAllPlatforms('when typing', (tester) async { | ||
await tester // | ||
.createDocument() | ||
|
@@ -1082,7 +1083,7 @@ void main() { | |
}); | ||
}); | ||
|
||
testWidgetsOnAllPlatforms('recognizes a second URL when typing and converts it to a link', (tester) async { | ||
testWidgetsOnAllPlatforms('inserts https scheme if it is missing', (tester) async { | ||
await tester // | ||
.createDocument() | ||
.withSingleEmptyParagraph() | ||
|
@@ -1092,35 +1093,30 @@ void main() { | |
// Place the caret at the beginning of the empty document. | ||
await tester.placeCaretInParagraph("1", 0); | ||
|
||
// Type text with two URLs | ||
await tester.typeImeText("https://www.google.com and https://flutter.dev "); | ||
// Type a URL. It shouldn't linkify until we add a space. | ||
await tester.typeImeText("www.google.com"); | ||
|
||
// Ensure both URLs are linkified with the correct URLs. | ||
final text = SuperEditorInspector.findTextInComponent("1"); | ||
// Type a space, to cause a linkify reaction. | ||
await tester.typeImeText(" "); | ||
|
||
expect(text.text, "https://www.google.com and https://flutter.dev "); | ||
expect( | ||
text.hasAttributionsThroughout( | ||
attributions: { | ||
LinkAttribution.fromUri(Uri.parse("https://www.google.com")), | ||
}, | ||
range: const SpanRange(0, 21), | ||
), | ||
isTrue, | ||
); | ||
// Ensure it's linkified with a URL schema. | ||
var text = SuperEditorInspector.findTextInComponent("1"); | ||
text = SuperEditorInspector.findTextInComponent("1"); | ||
|
||
expect(text.text, "www.google.com "); | ||
expect( | ||
text.hasAttributionsThroughout( | ||
attributions: { | ||
LinkAttribution.fromUri(Uri.parse("https://flutter.dev")), | ||
}, | ||
range: const SpanRange(27, 45), | ||
), | ||
isTrue, | ||
text.getAttributionSpansByFilter((a) => a is LinkAttribution), | ||
{ | ||
AttributionSpan( | ||
attribution: LinkAttribution.fromUri(Uri.parse("https://www.google.com")), | ||
start: 0, | ||
end: 13, | ||
), | ||
}, | ||
); | ||
}); | ||
|
||
testWidgetsOnAllPlatforms('recognizes a URL without www and converts it to a link', (tester) async { | ||
testWidgetsOnAllPlatforms('recognizes a URL without https and www and converts it to a link', (tester) async { | ||
await tester // | ||
.createDocument() | ||
.withSingleEmptyParagraph() | ||
|
@@ -1153,17 +1149,18 @@ void main() { | |
|
||
expect(text.text, "google.com "); | ||
expect( | ||
text.hasAttributionsThroughout( | ||
attributions: { | ||
LinkAttribution.fromUri(Uri.parse("https://google.com")), | ||
}, | ||
range: SpanRange(0, text.length - 2), | ||
), | ||
isTrue, | ||
text.getAttributionSpansByFilter((a) => a is LinkAttribution), | ||
{ | ||
AttributionSpan( | ||
attribution: LinkAttribution.fromUri(Uri.parse("https://google.com")), | ||
start: 0, | ||
end: 9, | ||
), | ||
}, | ||
); | ||
}); | ||
|
||
testWidgetsOnAllPlatforms('inserts https scheme if it is missing', (tester) async { | ||
testWidgetsOnAllPlatforms('recognizes a second URL when typing and converts it to a link', (tester) async { | ||
await tester // | ||
.createDocument() | ||
.withSingleEmptyParagraph() | ||
|
@@ -1173,25 +1170,134 @@ void main() { | |
// Place the caret at the beginning of the empty document. | ||
await tester.placeCaretInParagraph("1", 0); | ||
|
||
// Type a URL. It shouldn't linkify until we add a space. | ||
await tester.typeImeText("www.google.com"); | ||
// Type text with two URLs | ||
await tester.typeImeText("https://www.google.com and https://flutter.dev "); | ||
|
||
// Type a space, to cause a linkify reaction. | ||
await tester.typeImeText(" "); | ||
// Ensure both URLs are linkified with the correct URLs. | ||
final text = SuperEditorInspector.findTextInComponent("1"); | ||
|
||
expect(text.text, "https://www.google.com and https://flutter.dev "); | ||
expect( | ||
text.getAttributionSpansByFilter((a) => a is LinkAttribution), | ||
{ | ||
AttributionSpan( | ||
attribution: LinkAttribution.fromUri(Uri.parse("https://www.google.com")), | ||
start: 0, | ||
end: 21, | ||
), | ||
AttributionSpan( | ||
attribution: LinkAttribution.fromUri(Uri.parse("https://flutter.dev")), | ||
start: 27, | ||
end: 45, | ||
), | ||
}, | ||
); | ||
}); | ||
|
||
testWidgetsOnDesktop('recognizes a pasted URL with www and converts it to a link', (tester) async { | ||
await tester // | ||
.createDocument() | ||
.withSingleEmptyParagraph() | ||
.withInputSource(TextInputSource.ime) | ||
.pump(); | ||
|
||
// Place the caret at the beginning of the empty document. | ||
await tester.placeCaretInParagraph("1", 0); | ||
|
||
// Paste text with a URL | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please end the comment with a dot. |
||
tester.simulateClipboard(); | ||
await tester.setSimulatedClipboardContent("Hello https://www.google.com world"); | ||
// TODO: create and use something like tester.pressPasteAdaptive() | ||
if (debugDefaultTargetPlatformOverride == TargetPlatform.macOS) { | ||
await tester.pressCmdV(); | ||
} else { | ||
await tester.pressCtlV(); | ||
} | ||
|
||
// Ensure the URL is linkified | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please end the comment with a dot. |
||
final text = SuperEditorInspector.findTextInComponent("1"); | ||
expect(text.text, "Hello https://www.google.com world"); | ||
expect( | ||
text.getAttributionSpansByFilter((a) => a is LinkAttribution), | ||
{ | ||
AttributionSpan( | ||
attribution: LinkAttribution.fromUri(Uri.parse("https://www.google.com")), | ||
start: 6, | ||
end: 27, | ||
), | ||
}, | ||
); | ||
}); | ||
|
||
testWidgetsOnDesktop('recognizes a pasted URL and inserts https scheme if it is missing', (tester) async { | ||
await tester // | ||
.createDocument() | ||
.withSingleEmptyParagraph() | ||
.withInputSource(TextInputSource.ime) | ||
.pump(); | ||
|
||
// Place the caret at the beginning of the empty document. | ||
await tester.placeCaretInParagraph("1", 0); | ||
|
||
// Paste text with a URL. | ||
tester.simulateClipboard(); | ||
await tester.setSimulatedClipboardContent("Hello www.google.com world"); | ||
// TODO: create and use something like tester.pressPasteAdaptive() | ||
if (debugDefaultTargetPlatformOverride == TargetPlatform.macOS) { | ||
await tester.pressCmdV(); | ||
} else { | ||
await tester.pressCtlV(); | ||
} | ||
|
||
// Ensure it's linkified with a URL schema. | ||
var text = SuperEditorInspector.findTextInComponent("1"); | ||
text = SuperEditorInspector.findTextInComponent("1"); | ||
|
||
expect(text.text, "www.google.com "); | ||
expect(text.text, "Hello www.google.com world"); | ||
expect( | ||
text.hasAttributionsThroughout( | ||
attributions: { | ||
LinkAttribution.fromUri(Uri.parse("https://www.google.com")), | ||
}, | ||
range: SpanRange(0, text.length - 2), | ||
), | ||
isTrue, | ||
text.getAttributionSpansByFilter((a) => a is LinkAttribution), | ||
{ | ||
AttributionSpan( | ||
attribution: LinkAttribution.fromUri(Uri.parse("https://www.google.com")), | ||
start: 6, | ||
end: 19, | ||
), | ||
}, | ||
); | ||
}); | ||
|
||
testWidgetsOnDesktop('recognizes a pasted URL without https or www and converts it to a link', (tester) async { | ||
await tester // | ||
.createDocument() | ||
.withSingleEmptyParagraph() | ||
.withInputSource(TextInputSource.ime) | ||
.pump(); | ||
|
||
// Place the caret at the beginning of the empty document. | ||
await tester.placeCaretInParagraph("1", 0); | ||
|
||
// Paste text with a URL | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please end the comment with a dot. |
||
tester.simulateClipboard(); | ||
await tester.setSimulatedClipboardContent("Hello google.com world"); | ||
// TODO: create and use something like tester.pressPasteAdaptive() | ||
if (debugDefaultTargetPlatformOverride == TargetPlatform.macOS) { | ||
await tester.pressCmdV(); | ||
} else { | ||
await tester.pressCtlV(); | ||
} | ||
|
||
// Ensure the URL is linkified | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please end the comment with a dot. |
||
final text = SuperEditorInspector.findTextInComponent("1"); | ||
expect(text.text, "Hello google.com world"); | ||
expect( | ||
text.getAttributionSpansByFilter((a) => a is LinkAttribution), | ||
{ | ||
AttributionSpan( | ||
attribution: LinkAttribution.fromUri(Uri.parse("https://google.com")), | ||
start: 6, | ||
end: 15, | ||
), | ||
}, | ||
); | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please end the comment with a dot.