Escape folder path in selectors

This commit is contained in:
Vladimir Katushenok 2024-12-14 16:20:03 +11:00
parent c1e7567a6e
commit 3406e6e489
2 changed files with 5 additions and 5 deletions

View file

@ -409,7 +409,7 @@ export class FolderOverview {
}
getElFromOverview(path: string): HTMLElement | null {
const el = this.listEl.querySelector(`[data-path="${path}"]`) as HTMLElement | null;
const el = this.listEl.querySelector(`[data-path="${CSS.escape(path)}"]`) as HTMLElement | null;
return el;
}
@ -464,4 +464,4 @@ class CustomMarkdownRenderChild extends MarkdownRenderChild {
onunload() {
this.folderOverview.disconnectListeners();
}
}
}

View file

@ -125,7 +125,7 @@ export async function addCSSClassToTitleEL(path: string, cssClass: string, plugi
return;
}
fileExplorerItem.addClass(cssClass);
const viewHeaderItems = document.querySelectorAll(`[data-path="${path}"]`);
const viewHeaderItems = document.querySelectorAll(`[data-path="${CSS.escape(path)}"]`);
viewHeaderItems.forEach((item) => {
item.addClass(cssClass);
});
@ -134,7 +134,7 @@ export async function addCSSClassToTitleEL(path: string, cssClass: string, plugi
export function removeCSSClassFromEL(path: string | undefined, cssClass: string, plugin: FolderNotesPlugin) {
if (!path) return;
const fileExplorerItem = getEl(path, plugin);
const viewHeaderItems = document.querySelectorAll(`[data-path="${path}"]`);
const viewHeaderItems = document.querySelectorAll(`[data-path="${CSS.escape(path)}"]`);
viewHeaderItems.forEach((item) => {
item.removeClass(cssClass);
});
@ -152,4 +152,4 @@ export function getEl(path: string, plugin: FolderNotesPlugin): HTMLElement | nu
if (!fileExplorerItem) { return null; }
if (fileExplorerItem.selfEl) return fileExplorerItem.selfEl;
return fileExplorerItem.titleEl;
}
}