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
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/src/commands/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn acquire_app_settings_lock() -> std::sync::MutexGuard<'static, ()> {
const DESKTOP_STATE_KEY: &str = "desktopState";
const DESKTOP_STATE_VERSION: u64 = 5;
const MAX_RECENT_WORKSPACES: usize = 12;
const MIN_PANEL_WIDTH: f64 = 224.0;
const MIN_PANEL_WIDTH: f64 = 148.0;
const MAX_PANEL_WIDTH: f64 = 480.0;
const DEFAULT_LEFT_PANEL_WIDTH: f64 = 288.0;
const DEFAULT_RIGHT_PANEL_WIDTH: f64 = 320.0;
Expand Down
15 changes: 15 additions & 0 deletions apps/desktop/src/commands/commandRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const commandContext: DesktopCommandContext = {
toggleAssistant: () => undefined,
toggleBottomPanel: () => undefined,
toggleLivePreview: () => undefined,
moveTabLeft: () => undefined,
moveTabRight: () => undefined,
revealPanel: () => undefined,
revealLeftPanel: () => undefined,
openSettings: () => undefined,
Expand All @@ -25,10 +27,23 @@ const commandContext: DesktopCommandContext = {
};

describe("desktop command registry", () => {
it("runs tab movement through the shell and closes the palette", () => {
const moveTabLeft = vi.fn();
const moveTabRight = vi.fn();
const closePalette = vi.fn();
const context = { ...commandContext, moveTabLeft, moveTabRight, closePalette };
const registry = createDesktopCommandRegistry();
registry.get("move-tab-left")?.handler(context);
registry.get("move-tab-right")?.handler(context);
expect(moveTabLeft).toHaveBeenCalledOnce();
expect(moveTabRight).toHaveBeenCalledOnce();
expect(closePalette).toHaveBeenCalledTimes(2);
});
it("provides the shell commands needed by the command palette", () => {
const registry = createDesktopCommandRegistry();

expect(registry.entries().map((command) => command.id)).toEqual([
"move-tab-left", "move-tab-right",
"new-note", "search", "go-back", "go-forward",
"toggle-live-preview", "toggle-theme",
"toggle-explorer", "toggle-outline", "toggle-assistant", "toggle-bottom-panel",
Expand Down
14 changes: 14 additions & 0 deletions apps/desktop/src/commands/commandRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export interface DesktopCommandContext {
readonly toggleAssistant: () => void;
readonly toggleBottomPanel: () => void;
readonly toggleLivePreview: () => void;
readonly moveTabLeft: () => void;
readonly moveTabRight: () => void;
/** Reveals a panel by its fully-qualified id, opening its side popout — either dock. */
readonly revealPanel: (panelId: string) => void;
/** Reveals a left-side panel by id; admits registered extension panels too. */
Expand Down Expand Up @@ -96,6 +98,18 @@ const withClosePalette = (action: NoArgContextAction) => (context: DesktopComman

/** First-party command ownership and availability are explicit and testable. */
export const builtInDesktopCommands: readonly DesktopCommand[] = [
available({
id: "move-tab-left",
title: "Move tab left",
keywords: ["reorder"],
handler: withClosePalette("moveTabLeft")
}),
available({
id: "move-tab-right",
title: "Move tab right",
keywords: ["reorder"],
handler: withClosePalette("moveTabRight")
}),
available({
id: "new-note",
title: "New note",
Expand Down
19 changes: 0 additions & 19 deletions apps/desktop/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -186,25 +186,6 @@
}
}

/* The explorer header's create actions stay hidden until the header is
hovered, focused into, on a coarse pointer, or has its ⋯ menu open
(`data-open`). Kept as one named state machine rather than variant
classes: a `focus-within:opacity-100` + `opacity-0` pair is exactly what
this is, but class-list conflict checkers can't see the intent. */
@utility tn-explorer-create-reveal {
opacity: 0;
transition-property: opacity;
transition-duration: 150ms;
.group\/explorer-header:hover &,
&:focus-within,
&[data-open="true"] {
opacity: 1;
}
@media (pointer: coarse) {
opacity: 1;
}
}

/* CodeMirror's internal elements take layout and skin from the host div.
Declared here rather than as `[&_.cm-*]` arbitrary variants so the host's
own classes (`min-h-0`, `overflow-auto`, `cursor-text`) don't collide
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/settings/SettingsHeaderBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export function SettingsHeaderBar({

return (
<header
className="flex min-h-8 flex-none items-center justify-between gap-3 border-b border-border bg-editor px-[0.9rem] py-1 text-[0.72rem] text-muted-foreground max-[760px]:min-h-11 max-[760px]:gap-2 max-[760px]:px-2"
className="flex h-9 flex-none items-center justify-between gap-3 border-b border-border bg-editor px-[0.9rem] text-[0.72rem] text-muted-foreground max-[760px]:h-11 max-[760px]:gap-2 max-[760px]:px-2"
data-testid="settings-header-bar"
aria-label="Settings header"
>
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop/src/settings/SettingsImportExport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const SEEDED_APP_VALUES: Record<string, unknown> = {
...BASE_SEEDED_APP_VALUES,
"appearance.shellMode": "auto",
"editor.livePreview": true,
"editor.tabCycleOrder": "tab order",
"sync.settleAutomatically": true,
"sync.historyPolicy": "",
"sync.automatically": true,
Expand Down Expand Up @@ -144,7 +145,7 @@ describe("buildExportPayload", () => {
expect(keys).toContain("settings.showAdvanced");
expect(keys).not.toContain("sync.trigger");
expect(keys).not.toContain("sync.destination");
expect(keys).toHaveLength(19);
expect(keys).toHaveLength(20);
});
});

Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/settings/desktopState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe("desktop state persistence", () => {
)
).toEqual({
...DEFAULT_DESKTOP_STATE,
leftPanelWidth: 224,
leftPanelWidth: 148,
rightPanelWidth: 480,
bottomPanelOpen: true
});
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/settings/desktopState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isRecord } from "@thinkbrain/core";
const DESKTOP_STATE_VERSION = 5;
export const DESKTOP_STATE_KEY = "desktopState";
const MAX_RECENT_WORKSPACES = 12;
const MIN_PANEL_WIDTH = 224;
const MIN_PANEL_WIDTH = 148;
const MAX_PANEL_WIDTH = 480;
export const DEFAULT_LEFT_PANEL_WIDTH = 288;
export const DEFAULT_RIGHT_PANEL_WIDTH = 320;
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop/src/shell/DesktopShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ export function DesktopShell({ shell }: { readonly shell: ShellState }) {
onForward={() => dispatchTabs({ type: "goForward" })}
onSelectTab={(tabId) => dispatchTabs({ type: "activate", tabId })}
onRequestCloseTab={(tabId) => dispatchTabs({ type: "requestClose", tabId })}
onCloseOtherTabs={(tabId) => dispatchTabs({ type: "closeMultiple", tabId, scope: "others" })}
onCloseTabsToRight={(tabId) => dispatchTabs({ type: "closeMultiple", tabId, scope: "right" })}
onKeepTab={(tabId) => dispatchTabs({ type: "keep", tabId })}
onReorderTab={(tabId, toIndex) => dispatchTabs({ type: "reorder", tabId, toIndex })}
onNewTab={() => shell.openNewTab()}
onToggleRightPanel={shell.toggleRightPanel}
onOpenCommandPalette={shell.openPalette}
Expand Down
16 changes: 12 additions & 4 deletions apps/desktop/src/shell/ResizeHandle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import { cn } from "../lib/utils";
/**
* Thin draggable divider between shell panels.
*
* Renders a 1px column-resize handle. Pointer and keyboard events are delegated
* to the parent so it can drive the resize logic. Hidden below the 760px
* breakpoint where the multi-column layout collapses.
* Renders a 1px column-resize handle whose *grab area* is wider than its
* visual line: an invisible pseudo-element overhangs 4px into the panels on
* both sides, so the edge is easy to hit without shifting any layout (the
* same overhang VS Code uses). On hover the line thickens via box-shadow —
* also layout-neutral — so the target is visible as well as hittable.
* Pointer and keyboard events are delegated to the parent so it can drive
* the resize logic. Hidden below the 760px breakpoint where the
* multi-column layout collapses.
*/
export function ResizeHandle({
label,
Expand All @@ -29,7 +34,10 @@ export function ResizeHandle({
<button
type="button"
className={cn(
"relative flex-[0_0_1px] select-none touch-none p-0 border-0 bg-border cursor-col-resize hover:bg-primary focus-visible:bg-primary focus-visible:outline-none max-[760px]:hidden",
"relative flex-[0_0_1px] select-none touch-none p-0 border-0 bg-border cursor-col-resize hover:bg-primary focus-visible:bg-primary focus-visible:outline-none",
"after:absolute after:inset-y-0 after:-left-1 after:-right-1 after:content-['']",
"hover:shadow-[0_0_0_1px_var(--tn-color-primary)]",
"max-[760px]:hidden",
className
)}
aria-label={`${label}. Use arrow keys to resize.`}
Expand Down
96 changes: 96 additions & 0 deletions apps/desktop/src/shell/TabContextMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { isFileResourceTab, tabAccessibleName, type DesktopTab } from "../tabs/tabModel";
import { Menu, MenuButton, MenuSeparator, type MenuPosition } from "./Menu";

/** Where a tab's right-click menu was asked for, plus the tab it is about. */
export type TabMenuState = MenuPosition & { readonly tabId: string };

const NOT_IMPLEMENTED = "Not implemented yet";

/**
* Right-click menu for an open tab.
*
* Only placement is this component's — every behaviour (focus, arrow keys,
* Escape, closing on an outside pointer) is the shared {@link Menu}'s.
* "Close" routes through the same request-close path the close chip uses, so
* a dirty tab still earns its save/discard/cancel dialog.
*/
export function TabContextMenu({
menu,
tabs,
onClose,
onRequestCloseTab,
onCloseOtherTabs,
onCloseTabsToRight,
}: {
readonly menu: TabMenuState;
readonly tabs: readonly DesktopTab[];
readonly onClose: () => void;
readonly onRequestCloseTab: (tabId: string) => void;
readonly onCloseOtherTabs: (tabId: string) => void;
readonly onCloseTabsToRight: (tabId: string) => void;
}) {
const index = tabs.findIndex((tab) => tab.id === menu.tabId);
const tab = index < 0 ? null : tabs[index]!;
if (tab === null) return null;

const others = tabs.filter((candidate) => candidate.id !== tab.id);
const toRight = tabs.slice(index + 1);
// A multi-close has no dirty guard to offer — when a dirty tab sits in the
// target set the item is stubbed rather than silently skipping real work.
const othersDirty = others.some((candidate) => candidate.isDirty);
const rightDirty = toRight.some((candidate) => candidate.isDirty);

const resource = tab.resource;
const filePath =
isFileResourceTab(tab) && resource?.rootPath !== undefined && resource.relativePath !== undefined
? `${resource.rootPath}/${resource.relativePath}`
: null;

const copyPath = () => {
if (filePath === null) return;
void navigator.clipboard?.writeText(filePath)?.catch((error: unknown) => {
console.error("[titlebar] Could not copy the tab path to the clipboard.", error);
});
onClose();
};

return (
<Menu at={menu} label={`${tabAccessibleName(tab)} options`} onClose={onClose}>
<MenuButton
label="Close"
onClick={() => {
onClose();
onRequestCloseTab(tab.id);
}}
/>
<MenuButton
label="Close other tabs"
disabled={others.length === 0 || othersDirty}
title={othersDirty ? NOT_IMPLEMENTED : undefined}
onClick={() => {
onClose();
onCloseOtherTabs(tab.id);
}}
/>
<MenuButton
label="Close tabs to the right"
disabled={toRight.length === 0 || rightDirty}
title={rightDirty ? NOT_IMPLEMENTED : undefined}
onClick={() => {
onClose();
onCloseTabsToRight(tab.id);
}}
/>
<MenuSeparator />
{filePath !== null && (
<>
<MenuButton label="Copy path" onClick={copyPath} />
{/* No explorer reveal/select entry exists yet — stub until one does. */}
<MenuButton label="Reveal in explorer" disabled title={NOT_IMPLEMENTED} onClick={() => undefined} />
</>
)}
{/* Pinning is not part of the tab model — stub until it exists. */}
<MenuButton label="Pin tab" disabled title={NOT_IMPLEMENTED} onClick={() => undefined} />
</Menu>
);
}
Loading
Loading