Skip to content

Commit 96e18b0

Browse files
authored
ENG-921 - normalize tag comparison in observer (#470)
* normalize tag comparison in observer * use existing getCleanTag
1 parent 57825f9 commit 96e18b0

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

apps/roam/src/components/settings/NodeConfig.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ import createBlock from "roamjs-components/writes/createBlock";
2525
import updateBlock from "roamjs-components/writes/updateBlock";
2626
import DiscourseNodeSuggestiveRules from "./DiscourseNodeSuggestiveRules";
2727

28+
export const getCleanTagText = (tag: string): string => {
29+
return tag.replace(/^#+/, "").trim().toUpperCase();
30+
};
31+
2832
const ValidatedInputPanel = ({
2933
label,
3034
description,
@@ -215,10 +219,6 @@ const NodeConfig = ({
215219
true,
216220
);
217221

218-
const getCleanTagText = (tag: string): string => {
219-
return tag.replace(/^#+/, "").trim().toUpperCase();
220-
};
221-
222222
const validate = useCallback((tag: string, format: string) => {
223223
const cleanTag = getCleanTagText(tag);
224224

apps/roam/src/utils/initializeObserversAndListeners.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import { formatHexColor } from "~/components/settings/DiscourseNodeCanvasSetting
4949
import { getSetting } from "./extensionSettings";
5050
import { mountLeftSidebar } from "~/components/LeftSidebarView";
5151
import { getUidAndBooleanSetting } from "./getExportSettings";
52+
import { getCleanTagText } from "~/components/settings/NodeConfig";
5253

5354
const debounce = (fn: () => void, delay = 250) => {
5455
let timeout: number;
@@ -109,8 +110,11 @@ export const initObservers = async ({
109110
callback: (s: HTMLSpanElement) => {
110111
const tag = s.getAttribute("data-tag");
111112
if (tag) {
113+
const normalizedTag = getCleanTagText(tag);
114+
112115
for (const node of getDiscourseNodes()) {
113-
if (tag.toLowerCase() === node.tag?.toLowerCase()) {
116+
const normalizedNodeTag = node.tag ? getCleanTagText(node.tag) : "";
117+
if (normalizedTag === normalizedNodeTag) {
114118
renderNodeTagPopupButton(s, node, onloadArgs.extensionAPI);
115119
if (node.canvasSettings?.color) {
116120
s.style.color = formatHexColor(node.canvasSettings.color);

0 commit comments

Comments
 (0)