Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(electron): history navigation context menu not working
Elian Doran9d6bb306e7a5
diff --git a/apps/client/src/widgets/buttons/history_navigation.ts b/apps/client/src/widgets/buttons/history_navigation.tsindex 5c05defb6e..74eaf6acc4 100644--- a/apps/client/src/widgets/buttons/history_navigation.ts+++ b/apps/client/src/widgets/buttons/history_navigation.ts@@ -1,16 +1,11 @@import utils from "../../services/utils.js";-import contextMenu from "../../menus/context_menu.js";+import contextMenu, { MenuCommandItem } from "../../menus/context_menu.js";import treeService from "../../services/tree.js";import ButtonFromNoteWidget from "./button_from_note.js";import type FNote from "../../entities/fnote.js";import type { CommandNames } from "../../components/app_context.js";import type { WebContents } from "electron";--interface ContextMenuItem {- title: string;- idx: string;- uiIcon: string;-}+import link from "../../services/link.js";export default class HistoryNavigationButton extends ButtonFromNoteWidget {private webContents?: WebContents;@@ -47,24 +42,20 @@ export default class HistoryNavigationButton extends ButtonFromNoteWidget {return;}- let items: ContextMenuItem[] = [];+ let items: MenuCommandItem<string>[] = [];- const history = this.webContents.navigationHistory;- const activeIndex = history.getActiveIndex();+ const history = this.webContents.navigationHistory.getAllEntries();+ const activeIndex = this.webContents.navigationHistory.getActiveIndex();for (const idx in history) {- const url = history[idx];- const parts = url.split("#");- if (parts.length < 2) continue;-- const notePathWithTab = parts[1];- const notePath = notePathWithTab.split("-")[0];+ const { notePath } = link.parseNavigationStateFromUrl(history[idx].url);+ if (!notePath) continue;const title = await treeService.getNotePathTitle(notePath);items.push({title,- idx,+ command: idx,uiIcon:parseInt(idx) === activeIndex? "bx bx-radio-circle-marked" // compare with type coercion!@@ -84,9 +75,10 @@ export default class HistoryNavigationButton extends ButtonFromNoteWidget {x: e.pageX,y: e.pageY,items,- selectMenuItemHandler: (item: any) => {- if (item && item.idx && this.webContents) {- this.webContents.goToIndex(item.idx);+ selectMenuItemHandler: (item: MenuCommandItem<string>) => {+ if (item && item.command && this.webContents) {+ const idx = parseInt(item.command, 10);+ this.webContents.navigationHistory.goToIndex(idx);}}});