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

Commit 4f07592

Browse files
authored
Merge pull request #1732 from TriliumNext/notepath
Make each part of the note path clickable.
2 parents c2b5f0a + b7e7196 commit 4f07592

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

src/public/app/services/link.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,20 @@ function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent | JQuery.MouseDownEvent
278278
const { notePath, viewScope } = parseNavigationStateFromUrl(hrefLink);
279279

280280
const ctrlKey = utils.isCtrlKey(evt);
281+
const shiftKey = evt.shiftKey;
281282
const isLeftClick = "which" in evt && evt.which === 1;
282283
const isMiddleClick = "which" in evt && evt.which === 2;
283284
const targetIsBlank = ($link?.attr("target") === "_blank");
284285
const openInNewTab = (isLeftClick && ctrlKey) || isMiddleClick || targetIsBlank;
286+
const activate = (isLeftClick && ctrlKey && shiftKey) || (isMiddleClick && shiftKey);
287+
const openInNewWindow = isLeftClick && evt.shiftKey && !ctrlKey;
285288

286289
if (notePath) {
287-
if (openInNewTab) {
290+
if (openInNewWindow) {
291+
appContext.triggerCommand("openInWindow", { notePath, viewScope });
292+
} else if (openInNewTab) {
288293
appContext.tabManager.openTabWithNoteWithHoisting(notePath, {
289-
activate: targetIsBlank,
294+
activate: activate ? true : targetIsBlank,
290295
viewScope
291296
});
292297
} else if (isLeftClick) {

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)