diff --git a/lib/utils/link_resolver.dart b/lib/utils/link_resolver.dart index 765bc7f4..150748af 100644 --- a/lib/utils/link_resolver.dart +++ b/lib/utils/link_resolver.dart @@ -1,5 +1,6 @@ import 'package:path/path.dart' as p; +import 'package:gitjournal/core/link.dart'; import 'package:gitjournal/core/note.dart'; class LinkResolver { @@ -7,6 +8,13 @@ class LinkResolver { LinkResolver(this.inputNote); + Note resolveLink(Link l) { + var href = l.filePath; + href ??= '[[${l.term}]]'; + + return resolve(href); + } + Note resolve(String link) { var spec = link; var folder = inputNote.parent; diff --git a/lib/widgets/notes_backlinks.dart b/lib/widgets/notes_backlinks.dart index 12b1f19f..38de828b 100644 --- a/lib/widgets/notes_backlinks.dart +++ b/lib/widgets/notes_backlinks.dart @@ -9,6 +9,7 @@ import 'package:gitjournal/core/note.dart'; import 'package:gitjournal/core/notes_folder_fs.dart'; import 'package:gitjournal/features.dart'; import 'package:gitjournal/folder_views/common.dart'; +import 'package:gitjournal/utils/link_resolver.dart'; import 'package:gitjournal/widgets/pro_overlay.dart'; class NoteBacklinkRenderer extends StatefulWidget { @@ -39,15 +40,15 @@ class _NoteBacklinkRendererState extends State { // Log.d("NoteBacklinkRenderer Predicate", props: {"filePath": n.filePath}); var links = await n.fetchLinks(); + var linkResolver = LinkResolver(n); var matchedLink = links.firstWhere( (l) { - if (l.filePath != null) { - return l.filePath == widget.note.filePath; + var matchedNote = linkResolver.resolveLink(l); + if (matchedNote == null) { + return false; } - var term = widget.note.pathSpec(); - term = p.basenameWithoutExtension(term); - return term == l.term; + return matchedNote.filePath == widget.note.filePath; }, orElse: () => null, ); diff --git a/test/markdown_toolbar_test.dart b/test/markdown_toolbar_test.dart index 47b29903..abb202bb 100644 --- a/test/markdown_toolbar_test.dart +++ b/test/markdown_toolbar_test.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; + import 'package:test/test.dart'; import 'package:gitjournal/widgets/markdown_toolbar.dart';