Skip to content

Commit 28c3456

Browse files
committed
address PR comment
1 parent 3dadba0 commit 28c3456

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

apps/obsidian/src/utils/wikilinkDragHandler.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ class WikilinkDragHandleWidget extends WidgetType {
150150
}
151151
}
152152

153-
// Matches wikilinks [[...]] (not embeds ![[...]]) and markdown links [text](path)
154-
const INTERNAL_LINK_RE =
155-
/(?<!!)\[\[([^\]]+)\]\]|(?<!!)\[([^\]]+)\]\(([^)]+\.md)\)/g;
153+
// Matches wikilinks [[...]] and markdown links [text](path.md).
154+
// Embed exclusion (![[...]] and ![text](...)) is handled in the loop.
155+
const INTERNAL_LINK_RE = /\[\[([^\]]+)\]\]|\[([^\]]+)\]\(([^)]+\.md)\)/g;
156156

157157
const buildWidgetDecorations = (
158158
view: EditorView,
@@ -166,6 +166,10 @@ const buildWidgetDecorations = (
166166
INTERNAL_LINK_RE.lastIndex = 0;
167167

168168
while ((match = INTERNAL_LINK_RE.exec(text)) !== null) {
169+
let isEmbed = false;
170+
if (match.index > 0) isEmbed = text[match.index - 1] === "!";
171+
isEmbed = view.state.doc.sliceString(from - 1, from) === "!";
172+
if (isEmbed) continue;
169173
const matchEnd = from + match.index + match[0].length;
170174
const linkPath = extractLinkPath(match[0]);
171175
const widget = new WikilinkDragHandleWidget(linkPath, plugin);

0 commit comments

Comments
 (0)