Skip to content

Commit

Permalink
Jump to link targets and named elements
Browse files Browse the repository at this point in the history
  • Loading branch information
amake committed Dec 3, 2024
1 parent 64aef30 commit 2c2c98f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
11 changes: 11 additions & 0 deletions assets/test/links-local.org
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
- [[*Hogehoge][Local section link to nonexistent section]]
- [[id:nonexistent-id][Local ID link to nonexistent ID]]
- [[#hogehoge_id][Local custom ID link to nonexistent ID]]
- [[foo bar][Ambiguous link to dedicated target]]
- [[FOO BAR][Ambiguous link to dedicated target (case insensitive)]]
- [[named-block-here][Ambiguous link to named element]]
- [[NAMED-BLOCK-HERE][Ambiguous link to named element (case insensitive)]]

* Foobar
:PROPERTIES:
Expand All @@ -17,9 +21,16 @@

Foobar!

<<foo bar>>

* Bizzbuzz
:PROPERTIES:
:CUSTOM_ID: bizzbuzz_id
:END:

Bizzbuzz!

#+NAME: named-block-here
#+begin_src sh
echo hello, world
#+end_src
30 changes: 17 additions & 13 deletions lib/src/navigation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,14 @@ class _DocumentPageWrapper extends StatelessWidget {
errorHandler: (e) => WidgetsBinding.instance.addPostFrameCallback(
(_) => showErrorSnackBar(context, OrgroError.from(e))),
restorationId: 'org_page:${dataSource.id}',
child: DocumentPage(
layer: layer,
title: dataSource.name,
initialTarget: target,
initialMode: initialMode,
root: true,
child: OrgLocator(
child: DocumentPage(
layer: layer,
title: dataSource.name,
initialTarget: target,
initialMode: initialMode,
root: true,
),
),
);
},
Expand Down Expand Up @@ -187,13 +189,15 @@ Future<OrgTree?> narrow(
searchQuery: _searchPattern(viewSettings.queryString),
sparseQuery: _sparseQuery(viewSettings.filterData),
restorationId: 'org_narrow_$layer:${dataSource.id}',
child: DocumentPage(
layer: layer,
title: AppLocalizations.of(context)!
.pageTitleNarrow(dataSource.name),
initialQuery: viewSettings.queryString,
initialFilter: viewSettings.filterData,
root: false,
child: OrgLocator(
child: DocumentPage(
layer: layer,
title: AppLocalizations.of(context)!
.pageTitleNarrow(dataSource.name),
initialQuery: viewSettings.queryString,
initialFilter: viewSettings.filterData,
root: false,
),
),
);
}),
Expand Down
10 changes: 10 additions & 0 deletions lib/src/pages/document/links.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ extension LinkHandler on DocumentPageState {
return await _openExternalIdLink(link.location);
}

final handled = await _openLocalFallbackTargets(doc, link.location);
if (handled) return true;

// Handle as a general URL
try {
final url = extractUrl(doc, link);
Expand Down Expand Up @@ -142,6 +145,13 @@ extension LinkHandler on DocumentPageState {
return false;
}

Future<bool> _openLocalFallbackTargets(OrgTree doc, String target) async {
final locator = OrgLocator.of(context)!;
if (await locator.jumpToLinkTarget(target)) return true;
if (await locator.jumpToName(target)) return true;
return false;
}

Future<bool> _openFileInExternalApp(DataSource source) async {
final tmp = await getTemporaryAttachmentsDirectory();
final tmpFile =
Expand Down
8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -500,18 +500,18 @@ packages:
dependency: "direct main"
description:
name: org_flutter
sha256: "45a069dc864ebd81da7f6218ee67608b6b1d5dc12dbc09451c33866a9816a370"
sha256: a567fddeffe7d457dce8c509b9cc1d8da422b4a325389aacdad266fa23be3d6d
url: "https://pub.dev"
source: hosted
version: "7.13.2"
version: "8.0.1"
org_parser:
dependency: transitive
description:
name: org_parser
sha256: cb5ddbdab0526e6f86f78666643fa2d7ad03952a65054ca631a99d04d95d7990
sha256: "98ad7dfa9297791b5e4453bea844e1f63375c506ebe75ee887006075e87e1e3d"
url: "https://pub.dev"
source: hosted
version: "7.1.2"
version: "7.2.0"
path:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies:
google_fonts: ^6.0.0
http: ^1.1.0
intl: ^0.19.0
org_flutter: ^7.13.0
org_flutter: ^8.0.1
# org_flutter:
# path: ../org_flutter
path_provider: ^2.0.9
Expand Down

0 comments on commit 2c2c98f

Please sign in to comment.