From de21d8dc37e1eca90fe9e31687a45b59cfaeb626 Mon Sep 17 00:00:00 2001 From: Jinwoo-H Date: Fri, 1 May 2026 03:17:33 -0400 Subject: [PATCH] fix: doc links show grey when target missing, not always blue The resolution check returned true when the document list was empty (before storage was populated), making all links appear blue. Now returns false when no documents are loaded, correctly showing grey for unresolved targets. Co-authored-by: Orca --- .../components/editor/rich-markdown-doc-link.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/renderer/src/components/editor/rich-markdown-doc-link.ts b/src/renderer/src/components/editor/rich-markdown-doc-link.ts index 3c94e5eca4f..f7144fc50aa 100644 --- a/src/renderer/src/components/editor/rich-markdown-doc-link.ts +++ b/src/renderer/src/components/editor/rich-markdown-doc-link.ts @@ -16,7 +16,7 @@ const docLinkAutoConvertKey = new PluginKey('docLinkAutoConvert') function isDocLinkResolved(target: string, documents: MarkdownDocument[]): boolean { if (documents.length === 0) { - return true + return false } const index = createMarkdownDocumentIndex(documents) return resolveMarkdownDocLink(target, index).status === 'resolved' @@ -82,8 +82,11 @@ export const MarkdownDocLink = Node.create({ addNodeView() { const storage = this.storage as { documents: MarkdownDocument[] } - return ({ node }: { node: { type: { name: string }; attrs: { target?: string } } }) => { - const target = typeof node.attrs.target === 'string' ? node.attrs.target : '' + return ({ node }: { node: { type: { name: string }; attrs: Record } }) => { + const getTarget = (n: { attrs: Record }): string => + typeof n.attrs.target === 'string' ? n.attrs.target : '' + + const target = getTarget(node) const dom = document.createElement('span') dom.setAttribute('data-doc-link-target', target) dom.setAttribute('contenteditable', 'false') @@ -100,12 +103,14 @@ export const MarkdownDocLink = Node.create({ return { dom, - update: (updatedNode) => { + // Why: this fires on every transaction, including the no-op dispatched + // when the document list changes in storage. Re-checking resolution + // here keeps the blue/grey styling current without a full re-render. + update: (updatedNode: { type: { name: string }; attrs: Record }) => { if (updatedNode.type.name !== 'markdownDocLink') { return false } - const newTarget = - typeof updatedNode.attrs.target === 'string' ? updatedNode.attrs.target : '' + const newTarget = getTarget(updatedNode) dom.setAttribute('data-doc-link-target', newTarget) dom.textContent = newTarget applyResolutionClass(newTarget)