From ff641fd2b6c4de59d61b5abcb8a5d9c41a3a57f3 Mon Sep 17 00:00:00 2001 From: Aaron Madlon-Kay Date: Mon, 5 Apr 2021 09:32:57 +0900 Subject: [PATCH] Open relative links See #5 --- lib/src/pages/document.dart | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/src/pages/document.dart b/lib/src/pages/document.dart index 622baf0..c76fc99 100644 --- a/lib/src/pages/document.dart +++ b/lib/src/pages/document.dart @@ -247,10 +247,7 @@ class _DocumentPageState extends State with ViewSettingsState { constraints: const BoxConstraints(maxWidth: 800), child: OrgRootWidget( style: textStyle, - onLinkTap: (url) { - debugPrint('Launching URL: $url'); - return launch(url, forceSafariVC: false); - }, + onLinkTap: _openLink, onSectionLongPress: (section) => narrow(context, widget.dataSource, section), onLocalSectionLinkTap: (section) => @@ -292,6 +289,16 @@ class _DocumentPageState extends State with ViewSettingsState { ); } + Future _openLink(String url) { + if (looksLikeRelativePath(url) && url.endsWith('.org')) { + final resolved = widget.dataSource.resolveRelative(url); + return loadDocument(context, resolved); + } else { + debugPrint('Launching URL: $url'); + return launch(url, forceSafariVC: false); + } + } + bool? _hasRelativeLinks; bool get _askForDirectoryPermissions =>