From 9d6bb306e7a57f82c0c9f2ed892c061c4c1616b4 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 31 Aug 2025 19:39:54 +0300 Subject: [PATCH] fix(electron): history navigation context menu not working --- .../src/widgets/buttons/history_navigation.ts | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/apps/client/src/widgets/buttons/history_navigation.ts b/apps/client/src/widgets/buttons/history_navigation.ts index 5c05defb6..74eaf6acc 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[] = []; - 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) => { + if (item && item.command && this.webContents) { + const idx = parseInt(item.command, 10); + this.webContents.navigationHistory.goToIndex(idx); } } });