Skip to content

Commit 27d9ae8

Browse files
committed
Merge branch 'main' of github.com:TriliumNext/Trilium
2 parents 66bb639 + 35efd2a commit 27d9ae8

File tree

43 files changed

+507
-231
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+507
-231
lines changed

apps/client/src/components/app_context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ export type CommandMappings = {
270270
closeThisNoteSplit: CommandData;
271271
moveThisNoteSplit: CommandData & { isMovingLeft: boolean };
272272
jumpToNote: CommandData;
273+
openTodayNote: CommandData;
273274
commandPalette: CommandData;
274275

275276
// Keyboard shortcuts

apps/client/src/components/entrypoints.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,16 @@ export default class Entrypoints extends Component {
159159
this.openInWindowCommand({ notePath: "", hoistedNoteId: "root" });
160160
}
161161

162+
async openTodayNoteCommand() {
163+
const todayNote = await dateNoteService.getTodayNote();
164+
if (!todayNote) {
165+
console.warn("Missing today note.");
166+
return;
167+
}
168+
169+
await appContext.tabManager.openInSameTab(todayNote.noteId);
170+
}
171+
162172
async runActiveNoteCommand() {
163173
const noteContext = appContext.tabManager.getActiveContext();
164174
if (!noteContext) {

apps/client/src/entities/fnote.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ export default class FNote {
417417
return notePaths;
418418
}
419419

420-
getSortedNotePathRecords(hoistedNoteId = "root"): NotePathRecord[] {
420+
getSortedNotePathRecords(hoistedNoteId = "root", activeNotePath: string | null = null): NotePathRecord[] {
421421
const isHoistedRoot = hoistedNoteId === "root";
422422

423423
const notePaths: NotePathRecord[] = this.getAllNotePaths().map((path) => ({
@@ -428,7 +428,23 @@ export default class FNote {
428428
isHidden: path.includes("_hidden")
429429
}));
430430

431+
// Calculate the length of the prefix match between two arrays
432+
const prefixMatchLength = (path: string[], target: string[]) => {
433+
const diffIndex = path.findIndex((seg, i) => seg !== target[i]);
434+
return diffIndex === -1 ? Math.min(path.length, target.length) : diffIndex;
435+
};
436+
431437
notePaths.sort((a, b) => {
438+
if (activeNotePath) {
439+
const activeSegments = activeNotePath.split('/');
440+
const aOverlap = prefixMatchLength(a.notePath, activeSegments);
441+
const bOverlap = prefixMatchLength(b.notePath, activeSegments);
442+
// Paths with more matching prefix segments are prioritized
443+
// when the match count is equal, other criteria are used for sorting
444+
if (bOverlap !== aOverlap) {
445+
return bOverlap - aOverlap;
446+
}
447+
}
432448
if (a.isInHoistedSubTree !== b.isInHoistedSubTree) {
433449
return a.isInHoistedSubTree ? -1 : 1;
434450
} else if (a.isArchived !== b.isArchived) {
@@ -449,10 +465,11 @@ export default class FNote {
449465
* Returns the note path considered to be the "best"
450466
*
451467
* @param {string} [hoistedNoteId='root']
468+
* @param {string|null} [activeNotePath=null]
452469
* @return {string[]} array of noteIds constituting the particular note path
453470
*/
454-
getBestNotePath(hoistedNoteId = "root") {
455-
return this.getSortedNotePathRecords(hoistedNoteId)[0]?.notePath;
471+
getBestNotePath(hoistedNoteId = "root", activeNotePath: string | null = null) {
472+
return this.getSortedNotePathRecords(hoistedNoteId, activeNotePath)[0]?.notePath;
456473
}
457474

458475
/**

apps/client/src/services/tree.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,12 @@ async function resolveNotePathToSegments(notePath: string, hoistedNoteId = "root
2626
}
2727

2828
const path = notePath.split("/").reverse();
29-
30-
if (!path.includes("root")) {
31-
path.push("root");
32-
}
33-
3429
const effectivePathSegments: string[] = [];
3530
let childNoteId: string | null = null;
3631
let i = 0;
3732

38-
while (true) {
39-
if (i >= path.length) {
40-
break;
41-
}
42-
43-
const parentNoteId = path[i++];
33+
for (let i = 0; i < path.length; i++) {
34+
const parentNoteId = path[i];
4435

4536
if (childNoteId !== null) {
4637
const child = await froca.getNote(childNoteId, !logErrors);
@@ -65,7 +56,7 @@ async function resolveNotePathToSegments(notePath: string, hoistedNoteId = "root
6556
return null;
6657
}
6758

68-
if (!parents.some((p) => p.noteId === parentNoteId)) {
59+
if (!parents.some(p => p.noteId === parentNoteId) || (i === path.length - 1 && parentNoteId !== 'root')) {
6960
if (logErrors) {
7061
const parent = froca.getNoteFromCache(parentNoteId);
7162

@@ -77,7 +68,8 @@ async function resolveNotePathToSegments(notePath: string, hoistedNoteId = "root
7768
);
7869
}
7970

80-
const bestNotePath = child.getBestNotePath(hoistedNoteId);
71+
const activeNotePath = appContext.tabManager.getActiveContextNotePath();
72+
const bestNotePath = child.getBestNotePath(hoistedNoteId, activeNotePath);
8173

8274
if (bestNotePath) {
8375
const pathToRoot = bestNotePath.reverse().slice(1);
@@ -108,7 +100,9 @@ async function resolveNotePathToSegments(notePath: string, hoistedNoteId = "root
108100
if (!note) {
109101
throw new Error(`Unable to find note: ${notePath}.`);
110102
}
111-
const bestNotePath = note.getBestNotePath(hoistedNoteId);
103+
104+
const activeNotePath = appContext.tabManager.getActiveContextNotePath();
105+
const bestNotePath = note.getBestNotePath(hoistedNoteId, activeNotePath);
112106

113107
if (!bestNotePath) {
114108
throw new Error(`Did not find any path segments for '${note.toString()}', hoisted note '${hoistedNoteId}'`);

apps/client/src/services/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ export function reloadFrontendApp(reason?: string) {
1111
logInfo(`Frontend app reload: ${reason}`);
1212
}
1313

14-
window.location.reload();
14+
if (isElectron()) {
15+
dynamicRequire("@electron/remote").BrowserWindow.getFocusedWindow()?.reload();
16+
} else {
17+
window.location.reload();
18+
}
1519
}
1620

1721
export function restartDesktopApp() {

apps/client/src/widgets/dialogs/export.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ export default function ExportDialog() {
7979
values={[
8080
{ value: "html", label: t("export.format_html_zip") },
8181
{ value: "markdown", label: t("export.format_markdown") },
82-
{ value: "opml", label: t("export.format_opml") },
83-
{ value: "share", label: t("export.share-format") }
82+
{ value: "share", label: t("export.share-format") },
83+
{ value: "opml", label: t("export.format_opml") }
8484
]}
8585
/>
8686

apps/server/src/assets/doc_notes/en/User Guide/!!!meta.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/server/src/assets/doc_notes/en/User Guide/User Guide/Installation & Setup/Desktop Installation/System Requirements.html

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/server/src/assets/doc_notes/en/User Guide/User Guide/Installation & Setup/Server Installation/System Requirements.html

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)