From 8b34224377bc0f45c42ab423093f27ba52cdd118 Mon Sep 17 00:00:00 2001 From: sid597 Date: Sat, 6 Sep 2025 00:54:21 +0530 Subject: [PATCH] handle node tags with # in front and update placeholder to use # --- apps/roam/src/components/DiscourseNodeMenu.tsx | 10 +++++++--- apps/roam/src/components/settings/NodeConfig.tsx | 2 +- apps/roam/src/utils/initializeObserversAndListeners.ts | 4 +++- apps/roam/src/utils/renderNodeTagPopup.tsx | 6 ++++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/roam/src/components/DiscourseNodeMenu.tsx b/apps/roam/src/components/DiscourseNodeMenu.tsx index 62160488c..24fd56602 100644 --- a/apps/roam/src/components/DiscourseNodeMenu.tsx +++ b/apps/roam/src/components/DiscourseNodeMenu.tsx @@ -113,7 +113,7 @@ const NodeMenu = ({ setTimeout(() => { const currentText = textarea.value; const cursorPos = textarea.selectionStart; - const textToInsert = `#${tag} `; + const textToInsert = `#${tag.replace(/^#/, "")} `; const newText = `${currentText.substring( 0, @@ -249,9 +249,13 @@ const NodeMenu = ({ setActiveIndex(i)} diff --git a/apps/roam/src/components/settings/NodeConfig.tsx b/apps/roam/src/components/settings/NodeConfig.tsx index 0b1bd5eca..70b7c92c1 100644 --- a/apps/roam/src/components/settings/NodeConfig.tsx +++ b/apps/roam/src/components/settings/NodeConfig.tsx @@ -229,7 +229,7 @@ const NodeConfig = ({ onChange={handleTagChange} onBlur={handleTagBlur} error={tagError} - placeholder={`${node.text}`} + placeholder={`#${node.text.toLowerCase()}`} /> } diff --git a/apps/roam/src/utils/initializeObserversAndListeners.ts b/apps/roam/src/utils/initializeObserversAndListeners.ts index 8a4f11bfd..1ea56ec2e 100644 --- a/apps/roam/src/utils/initializeObserversAndListeners.ts +++ b/apps/roam/src/utils/initializeObserversAndListeners.ts @@ -65,7 +65,9 @@ const refreshDiscourseNodeCache = () => { {} as Record, ); discourseTagSet = new Set( - discourseNodes.flatMap((n) => (n.tag ? [n.tag.toLowerCase()] : [])), + discourseNodes.flatMap((n) => + n.tag ? [n.tag.replace(/^#/, "").toLowerCase()] : [], + ), ); }; diff --git a/apps/roam/src/utils/renderNodeTagPopup.tsx b/apps/roam/src/utils/renderNodeTagPopup.tsx index cf268b62d..eee3ed0d8 100644 --- a/apps/roam/src/utils/renderNodeTagPopup.tsx +++ b/apps/roam/src/utils/renderNodeTagPopup.tsx @@ -19,7 +19,9 @@ export const renderNodeTagPopupButton = ( const textContent = parent.textContent?.trim() || ""; const tagAttr = parent.getAttribute("data-tag") || textContent; const tag = tagAttr.replace(/^#/, "").toLowerCase(); - const matchedNode = discourseNodes.find((n) => n.tag?.toLowerCase() === tag); + const matchedNode = discourseNodes.find( + (n) => n.tag?.replace(/^#/, "").toLowerCase() === tag, + ); if (!matchedNode) return; @@ -64,7 +66,7 @@ export const renderNodeTagPopupButton = ( initialTitle: cleanedBlockText, }); }} - text={`Create ${matchedNode.text}`} + text={`Create ${matchedNode.tag?.replace(/^#/, "").toLowerCase()}`} /> } target={