Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions apps/desktop/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ let menuState: MenuState = {
hasWorkspace: false,
hasMarkdownNoteOpen: false,
isSourceMode: false,
canGoBack: false,
canGoForward: false,
};
let updateState: DesktopUpdateState = {
isSupported: supportsAutoUpdates,
Expand Down Expand Up @@ -806,6 +808,21 @@ function buildMenu() {
{
label: "View",
submenu: [
{
id: "go-back",
label: "Go Back",
accelerator: "CmdOrCtrl+[",
enabled: menuState.canGoBack,
click: () => sendToRenderer("desktop:menu-go-back"),
},
{
id: "go-forward",
label: "Go Forward",
accelerator: "CmdOrCtrl+]",
enabled: menuState.canGoForward,
click: () => sendToRenderer("desktop:menu-go-forward"),
},
{ type: "separator" },
{
id: "zoom-in",
label: "Zoom In",
Expand Down Expand Up @@ -1577,6 +1594,8 @@ function registerIpc() {
hasWorkspace: state.hasWorkspace === true,
hasMarkdownNoteOpen: state.hasMarkdownNoteOpen === true,
isSourceMode: state.isSourceMode === true,
canGoBack: state.canGoBack === true,
canGoForward: state.canGoForward === true,
};
buildMenu();
});
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ const desktopApi = {
subscribe("desktop:menu-sync-workspace", callback),
onMenuToggleTerminal: (callback) =>
subscribe("desktop:menu-toggle-terminal", callback),
onMenuGoBack: (callback) => subscribe("desktop:menu-go-back", callback),
onMenuGoForward: (callback) => subscribe("desktop:menu-go-forward", callback),
onMenuToggleSourceMode: (callback) =>
subscribe("desktop:menu-toggle-source-mode", callback),
onWindowFocus: (callback) => subscribe("desktop:window-focus", callback),
Expand Down
31 changes: 28 additions & 3 deletions apps/desktop/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import {
createWorkspaceWithSidebar,
forceKeepLocalEdits,
getPendingRenameTarget,
goBack,
goForward,
handleExternalFileChange,
loadPath,
openWorkspace,
Expand All @@ -58,6 +60,8 @@ import {
toggleTerminal,
updateEditorContent,
} from "./store/actions";
import { canGoBack, canGoForward } from "./store/history";
import { useHistoryNav } from "./store/hooks";
import {
chatCommandStore,
sidebarOpenStore,
Expand Down Expand Up @@ -102,6 +106,8 @@ function App() {
const sidebarOpen = useStoreValue(sidebarOpenStore);
const terminalPosition = useStoreValue(terminalPositionStore);
const hasWorkspace = workspacePath !== null;
const { canGoBack: menuCanGoBack, canGoForward: menuCanGoForward } =
useHistoryNav();
const [scrollContainerEl, setScrollContainerEl] =
useState<HTMLDivElement | null>(null);
const [settingsOpen, setSettingsOpen] = useState(false);
Expand Down Expand Up @@ -201,16 +207,32 @@ function App() {
hasMarkdownNoteOpen:
typeof currentPath === "string" && hasMarkdownExtension(currentPath),
isSourceMode: state.viewMode === "source",
canGoBack: menuCanGoBack,
canGoForward: menuCanGoForward,
});
}, [hasWorkspace, state.currentPath, state.viewMode]);
}, [
hasWorkspace,
menuCanGoBack,
menuCanGoForward,
state.currentPath,
state.viewMode,
]);

useEffect(() => {
if (!sidebarOpen) setFocusedSidebarPath(null);
}, [sidebarOpen]);

useEffect(() => {
const onKeyDown = async (event: KeyboardEvent) => {
if (keymatch(event, "CmdOrCtrl+N")) {
if (keymatch(event, "CmdOrCtrl+[")) {
if (!canGoBack()) return;
event.preventDefault();
await goBack();
} else if (keymatch(event, "CmdOrCtrl+]")) {
if (!canGoForward()) return;
event.preventDefault();
await goForward();
} else if (keymatch(event, "CmdOrCtrl+N")) {
event.preventDefault();
await createMarkdownFile();
} else if (keymatch(event, "CmdOrCtrl+,")) {
Expand Down Expand Up @@ -295,6 +317,8 @@ function App() {
),
desktopApi.onMenuSyncWorkspace(() => void refreshFiles()),
desktopApi.onMenuToggleTerminal(() => toggleTerminal()),
desktopApi.onMenuGoBack(() => void goBack()),
desktopApi.onMenuGoForward(() => void goForward()),
desktopApi.onMenuToggleSourceMode(() => {
const current = viewerStore.get();
if (
Expand Down Expand Up @@ -349,7 +373,8 @@ function App() {
? workspace.lastOpenedPaths[workspace.workspacePath]
: undefined);
if (lastPath) {
await loadPath(lastPath);
// Restore must stay quiet when the remembered file was deleted on disk.
await loadPath(lastPath, { missing: "silent" });
}
};
void init();
Expand Down
36 changes: 36 additions & 0 deletions apps/desktop/src/components/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
import { useStoreValue } from "@simplestack/store/react";
import { type CSSProperties, useEffect, useState } from "react";
import { toast } from "sonner";
import MingcuteArrowLeftLine from "~icons/mingcute/arrow-left-line";
import MingcuteArrowRightLine from "~icons/mingcute/arrow-right-line";
import MingcuteCodeLine from "~icons/mingcute/code-line";
import MingcuteCopy2Line from "~icons/mingcute/copy-2-line";
import MingcuteFolderOpenLine from "~icons/mingcute/folder-open-line";
Expand All @@ -17,12 +19,15 @@ import { copyText } from "../lib/clipboard";
import { hasMarkdownExtension } from "../lib/filePath";
import { revealFileLabel } from "../lib/revealFile";
import {
goBack,
goForward,
renameCurrentMarkdownFile,
requestChatAboutNote,
setViewerMode,
toggleSidebar,
toggleTerminal,
} from "../store/actions";
import { useHistoryNav } from "../store/hooks";
import {
currentPathStore,
sidebarOpenStore,
Expand Down Expand Up @@ -65,6 +70,7 @@ export function Toolbar({
platformInset={!isFullScreen}
rootProps={{ style: dragRegionStyle }}
onToggleSidebar={toggleSidebar}
leftSlot={<NavigationControls />}
onRenameCurrentPath={(nextName) =>
void renameCurrentMarkdownFile(nextName)
}
Expand All @@ -91,6 +97,36 @@ export function Toolbar({
);
}

function NavigationControls() {
const { canGoBack, canGoForward } = useHistoryNav();
const backLabel = `Go Back (${formatShortcut("CmdOrCtrl+[")})`;
const forwardLabel = `Go Forward (${formatShortcut("CmdOrCtrl+]")})`;
return (
<>
<Button
variant="ghost"
size="icon-sm"
aria-label={backLabel}
title={backLabel}
disabled={!canGoBack}
onClick={() => void goBack()}
>
<MingcuteArrowLeftLine className="size-4" />
</Button>
<Button
variant="ghost"
size="icon-sm"
aria-label={forwardLabel}
title={forwardLabel}
disabled={!canGoForward}
onClick={() => void goForward()}
>
<MingcuteArrowRightLine className="size-4" />
</Button>
</>
);
}

function NoteActionsMenu({
path,
canChatAboutNote,
Expand Down
4 changes: 4 additions & 0 deletions apps/desktop/src/desktopApi/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export type MenuState = {
hasWorkspace: boolean;
hasMarkdownNoteOpen: boolean;
isSourceMode: boolean;
canGoBack: boolean;
canGoForward: boolean;
};

export type DesktopUpdateStatus =
Expand Down Expand Up @@ -136,6 +138,8 @@ export type DesktopApi = {
onMenuShowWorkspaceSwitcher(callback: () => void): Unsubscribe;
onMenuSyncWorkspace(callback: () => void): Unsubscribe;
onMenuToggleTerminal(callback: () => void): Unsubscribe;
onMenuGoBack(callback: () => void): Unsubscribe;
onMenuGoForward(callback: () => void): Unsubscribe;
onMenuToggleSourceMode(callback: () => void): Unsubscribe;
onWindowFocus(callback: () => void): Unsubscribe;
onFullScreenChange(callback: (isFullScreen: boolean) => void): Unsubscribe;
Expand Down
Loading
Loading