Skip to content

Commit

Permalink
refactor: applying suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony-MK committed Sep 1, 2023
1 parent 4de8a63 commit d1b7500
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,26 @@ KeyEventResult _openLinksHandler(

// A set to store the links which have been opened
// to prevent opening new tabs for the same link
Set<String> openedLinks = {};
final openedLinks = <String>{};

for (final node in nodes) {
for (final operation in node.delta!) {
final link = operation.attributes?[BuiltInAttributeKey.href];
if (link == null || openedLinks.contains(link)) continue;
final delta = node.delta;
if (delta == null) {
continue;
}

// Get all links in the node
final links = delta
.map<String?>((op) => op.attributes?[AppFlowyRichTextKeys.href])
.whereNotNull()
.toSet()
.difference(openedLinks);

openedLinks.add(link);
for (final link in links) {
safeLaunchUrl(link);
}

openedLinks.addAll(links);
}

return KeyEventResult.handled;
Expand Down

0 comments on commit d1b7500

Please sign in to comment.