From d1b750083776be69e0ea8c908890e578542921eb Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Fri, 1 Sep 2023 03:22:16 +0300 Subject: [PATCH] refactor: applying suggestion --- .../open_links_command.dart | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/src/editor/editor_component/service/shortcuts/command_shortcut_events/open_links_command.dart b/lib/src/editor/editor_component/service/shortcuts/command_shortcut_events/open_links_command.dart index 9945d947f..80750395d 100644 --- a/lib/src/editor/editor_component/service/shortcuts/command_shortcut_events/open_links_command.dart +++ b/lib/src/editor/editor_component/service/shortcuts/command_shortcut_events/open_links_command.dart @@ -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 openedLinks = {}; + final openedLinks = {}; 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((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;