Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit b86407b

Browse files
committed
Make each part of the note path clickable.
1 parent b875717 commit b86407b

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

src/public/app/widgets/ribbon_widgets/note_paths.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ const TPL = /*html*/`
1919
margin-top: 10px;
2020
}
2121
22-
.note-path-list .path-current {
22+
.note-path-list .path-current a {
2323
font-weight: bold;
2424
}
2525
26-
.note-path-list .path-archived {
26+
.note-path-list .path-archived a {
2727
color: var(--muted-text-color) !important;
2828
}
2929
30-
.note-path-list .path-search {
30+
.note-path-list .path-search a {
3131
font-style: italic;
3232
}
3333
</style>
@@ -72,7 +72,7 @@ export default class NotePathsWidget extends NoteContextAwareWidget {
7272
this.$notePathList.empty();
7373

7474
if (!this.note || this.noteId === "root") {
75-
this.$notePathList.empty().append(await this.getRenderedPath("root"));
75+
this.$notePathList.empty().append(await this.getRenderedPath(["root"]));
7676

7777
return;
7878
}
@@ -88,50 +88,62 @@ export default class NotePathsWidget extends NoteContextAwareWidget {
8888
const renderedPaths = [];
8989

9090
for (const notePathRecord of sortedNotePaths) {
91-
const notePath = notePathRecord.notePath.join("/");
91+
const notePath = notePathRecord.notePath;
9292

9393
renderedPaths.push(await this.getRenderedPath(notePath, notePathRecord));
9494
}
9595

9696
this.$notePathList.empty().append(...renderedPaths);
9797
}
9898

99-
async getRenderedPath(notePath: string, notePathRecord: NotePathRecord | null = null) {
100-
const title = await treeService.getNotePathTitle(notePath);
101-
102-
const $noteLink = await linkService.createLink(notePath, { title });
103-
104-
$noteLink.find("a").addClass("no-tooltip-preview tn-link");
99+
async getRenderedPath(notePath: string[], notePathRecord: NotePathRecord | null = null) {
100+
const $pathItem = $("<li>");
101+
const pathSegments: string[] = [];
102+
const lastIndex = notePath.length - 1;
103+
104+
for (let i = 0; i < notePath.length; i++) {
105+
const noteId = notePath[i];
106+
pathSegments.push(noteId);
107+
const title = await treeService.getNoteTitle(noteId);
108+
const $noteLink = await linkService.createLink(pathSegments.join("/"), { title });
109+
110+
$noteLink.find("a").addClass("no-tooltip-preview tn-link");
111+
$pathItem.append($noteLink);
112+
113+
if (i != lastIndex) {
114+
$pathItem.append(" / ");
115+
}
116+
}
105117

106118
const icons = [];
107119

108-
if (this.notePath === notePath) {
109-
$noteLink.addClass("path-current");
120+
if (this.notePath === notePath.join("/")) {
121+
$pathItem.addClass("path-current");
110122
}
111123

112124
if (!notePathRecord || notePathRecord.isInHoistedSubTree) {
113-
$noteLink.addClass("path-in-hoisted-subtree");
125+
$pathItem.addClass("path-in-hoisted-subtree");
114126
} else {
115127
icons.push(`<span class="bx bx-trending-up" title="${t("note_paths.outside_hoisted")}"></span>`);
116128
}
117129

118130
if (notePathRecord?.isArchived) {
119-
$noteLink.addClass("path-archived");
131+
$pathItem.addClass("path-archived");
120132

121133
icons.push(`<span class="bx bx-archive" title="${t("note_paths.archived")}"></span>`);
122134
}
123135

124136
if (notePathRecord?.isSearch) {
125-
$noteLink.addClass("path-search");
137+
$pathItem.addClass("path-search");
126138

127139
icons.push(`<span class="bx bx-search" title="${t("note_paths.search")}"></span>`);
128140
}
129141

130142
if (icons.length > 0) {
131-
$noteLink.append(` ${icons.join(" ")}`);
143+
$pathItem.append(` ${icons.join(" ")}`);
132144
}
133145

134-
return $("<li>").append($noteLink);
146+
return $pathItem;
135147
}
136148

137149
entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {

0 commit comments

Comments
 (0)