-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Super Editor] - Make emails clickable with "mailto:", and linkify ap…
- Loading branch information
1 parent
ee55d19
commit 85a49b2
Showing
9 changed files
with
941 additions
and
499 deletions.
There are no files selected for viewing
136 changes: 136 additions & 0 deletions
136
super_editor/example/lib/demos/interaction_spot_checks/url_launching_spot_checks.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:super_editor/super_editor.dart'; | ||
import 'package:super_editor_markdown/super_editor_markdown.dart'; | ||
|
||
import 'spot_check_scaffold.dart'; | ||
|
||
class UrlLauncherSpotChecks extends StatefulWidget { | ||
const UrlLauncherSpotChecks({super.key}); | ||
|
||
@override | ||
State<UrlLauncherSpotChecks> createState() => _UrlLauncherSpotChecksState(); | ||
} | ||
|
||
class _UrlLauncherSpotChecksState extends State<UrlLauncherSpotChecks> { | ||
late final Editor _editor; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
|
||
_editor = createDefaultDocumentEditor( | ||
document: deserializeMarkdownToDocument(''' | ||
# Linkification Spot Check | ||
In this spot check, we create a variety of linkification scenarios. We expect each link to be linkified, and to take the expect action when tapped. | ||
## Markdown Links (with schemes) | ||
[https://google.com](https://google.com) | ||
[mailto:[email protected]](mailto:[email protected]) | ||
[obsidian://open?vault=my-vault](obsidian://open?vault=my-vault) | ||
## Markdown Links (no schemes) | ||
[google.com](google.com) | ||
[[email protected]]([email protected]) | ||
## Pasted Links | ||
The first set of pasted links are all pasted together within a single block of text. Then the same links are pasted with one link per line. | ||
'''), | ||
composer: MutableDocumentComposer(), | ||
); | ||
|
||
_pasteLinks(); | ||
} | ||
|
||
Future<void> _pasteLinks() async { | ||
final links = ''' | ||
google.com https://google.com [email protected] mailto:[email protected] obsidian://open?vault=my-vault | ||
google.com | ||
https://google.com | ||
[email protected] | ||
mailto:[email protected] | ||
obsidian://open?vault=my-vault | ||
'''; | ||
|
||
// Put the text on the clipboard. | ||
await Clipboard.setData(ClipboardData(text: links)); | ||
|
||
// Place the caret at the end of the document. | ||
// TODO: Add a startPosition and endPosition to `Document`. | ||
_editor.execute([ | ||
ChangeSelectionRequest( | ||
DocumentSelection.collapsed( | ||
position: DocumentPosition( | ||
nodeId: _editor.document.last.id, | ||
nodePosition: (_editor.document.last as TextNode).endPosition, | ||
), | ||
), | ||
SelectionChangeType.placeCaret, | ||
SelectionReason.userInteraction, | ||
), | ||
]); | ||
|
||
// Paste the text from the clipboard, which should include a linkification reaction. | ||
CommonEditorOperations( | ||
editor: _editor, | ||
document: _editor.document, | ||
composer: _editor.composer, | ||
documentLayoutResolver: () => throw UnimplementedError(), | ||
).paste(); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_editor.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SpotCheckScaffold( | ||
content: SuperEditor( | ||
editor: _editor, | ||
stylesheet: defaultStylesheet.copyWith( | ||
addRulesAfter: [ | ||
..._darkModeStyles, | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
final _darkModeStyles = [ | ||
StyleRule( | ||
BlockSelector.all, | ||
(doc, docNode) { | ||
return { | ||
Styles.textStyle: const TextStyle( | ||
color: Color(0xFFCCCCCC), | ||
), | ||
}; | ||
}, | ||
), | ||
StyleRule( | ||
const BlockSelector("header1"), | ||
(doc, docNode) { | ||
return { | ||
Styles.textStyle: const TextStyle( | ||
color: Color(0xFF888888), | ||
), | ||
}; | ||
}, | ||
), | ||
StyleRule( | ||
const BlockSelector("header2"), | ||
(doc, docNode) { | ||
return { | ||
Styles.textStyle: const TextStyle( | ||
color: Color(0xFF888888), | ||
), | ||
}; | ||
}, | ||
), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.