Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(open-knowledge): portal the worktree submenu so it isn't clipped off-screen (#2537)

Andrew Mikofalvy1c56d4d16b07
diff --git a/packages/app/src/components/ProjectSwitcher.dom.test.tsx b/packages/app/src/components/ProjectSwitcher.dom.test.tsx
index a0af8f40c..7a10f4006 100644
--- a/packages/app/src/components/ProjectSwitcher.dom.test.tsx
+++ b/packages/app/src/components/ProjectSwitcher.dom.test.tsx
@@ -45,6 +45,11 @@ mock.module('@/components/ui/dropdown-menu', () => ({
DropdownMenuLabel: ({ children, ...props }: ItemProps) => <div {...props}>{children}</div>,
DropdownMenuSeparator: () => <hr />,
DropdownMenuTrigger: ({ children }: { children?: ReactNode }) => <>{children}</>,
+ // RecentProjectsMenu's worktree flyout wraps its SubContent in
+ // DropdownMenuPortal (escapes the menu's overflow clip). Passthrough here — the
+ // real portal-to-body isn't observable in jsdom and doesn't affect this file's
+ // hoisted-flyout + close-on-scroll assertions.
+ DropdownMenuPortal: ({ children }: { children?: ReactNode }) => <>{children}</>,
DropdownMenuSub: ({ children, open, onOpenChange }: MenuProps) => (
<SubStateContext value={{ open: !!open, onOpenChange: onOpenChange ?? (() => {}) }}>
{children}
@@ -84,7 +89,12 @@ mock.module('@/components/ui/dropdown-menu', () => ({
</div>
);
},
- DropdownMenuSubContent: ({ children, sideOffset: _sideOffset, ...props }: ItemProps) => {
+ DropdownMenuSubContent: ({
+ children,
+ sideOffset: _sideOffset,
+ avoidCollisions: _avoidCollisions,
+ ...props
+ }: ItemProps) => {
const { open } = use(SubStateContext);
if (!open) return null;
return <div {...props}>{children}</div>;
diff --git a/packages/app/src/components/RecentProjectsMenu.dom.test.tsx b/packages/app/src/components/RecentProjectsMenu.dom.test.tsx
index 8de8b9f0e..5a52ef060 100644
--- a/packages/app/src/components/RecentProjectsMenu.dom.test.tsx
+++ b/packages/app/src/components/RecentProjectsMenu.dom.test.tsx
@@ -41,6 +41,15 @@ mock.module('@/components/ui/dropdown-menu', () => ({
</div>
),
DropdownMenuLabel: ({ children, ...props }: ItemProps) => <div {...props}>{children}</div>,
+ // The worktree flyout content is wrapped in DropdownMenuPortal so it escapes
+ // the project menu's overflow-x-hidden clip (see RecentProjectsMenu's
+ // WorktreeFlyout doc). The real Portal renders into document.body; here it is a
+ // marked passthrough container so the portal-presence test can assert the
+ // SubContent is routed through it. jsdom has no layout, so this asserts the
+ // wiring (regression guard), not the off-screen geometry.
+ DropdownMenuPortal: ({ children }: { children?: ReactNode }) => (
+ <div data-slot="dropdown-menu-portal">{children}</div>
+ ),
DropdownMenuSub: ({
children,
open,
@@ -94,8 +103,9 @@ mock.module('@/components/ui/dropdown-menu', () => ({
DropdownMenuSubContent: ({
children,
sideOffset: _sideOffset,
+ avoidCollisions: _avoidCollisions,
...props
- }: ItemProps & { sideOffset?: number }) => {
+ }: ItemProps & { sideOffset?: number; avoidCollisions?: boolean }) => {
const { open, onOpenChange } = use(SubStateContext);
if (!open) return null;
// role="menu" mirrors the real DropdownMenuSubContent and satisfies the
@@ -327,6 +337,25 @@ describe('RecentProjectsMenu — grouped browse (no query)', () => {
expect(bridge.project.open).not.toHaveBeenCalled();
});
+ test('the open flyout content is rendered through DropdownMenuPortal (escapes the menu overflow clip)', async () => {
+ // Regression guard for the off-screen clip: shadcn's DropdownMenuSubContent
+ // is NOT portaled by default, so inline it was clipped by the recents list's
+ // overflow-x-hidden and never flipped left near the window edge. The fix
+ // wraps it in DropdownMenuPortal. jsdom can't verify the resulting geometry
+ // (no layout), but it CAN assert the SubContent is routed through the portal
+ // wrapper — drop the wrapper and this fails. (The visual "flips left / fits
+ // on screen" behavior must be confirmed live in the Electron app.)
+ renderMenu({
+ recents: [
+ main('/repo', '/repo/.git'),
+ worktree('/repo/.ok/worktrees/dev', '/repo/.git', '/repo', 'dev'),
+ ],
+ });
+ fireEvent.mouseEnter(screen.getByTestId('project-switcher-group-/repo'));
+ const flyout = await screen.findByTestId('project-switcher-flyout-/repo');
+ expect(flyout.closest('[data-slot="dropdown-menu-portal"]')).not.toBeNull();
+ });
+
test('the flyout closes when the pointer leaves both the row and the flyout (close-on-hover-out)', async () => {
renderMenu({
recents: [
diff --git a/packages/app/src/components/RecentProjectsMenu.tsx b/packages/app/src/components/RecentProjectsMenu.tsx
index 7e5291524..cb291e776 100644
--- a/packages/app/src/components/RecentProjectsMenu.tsx
+++ b/packages/app/src/components/RecentProjectsMenu.tsx
@@ -39,6 +39,7 @@ import { toast } from 'sonner';
import {
DropdownMenuItem,
DropdownMenuLabel,
+ DropdownMenuPortal,
DropdownMenuSub,
DropdownMenuSubContent,
DropdownMenuSubTrigger,
@@ -413,9 +414,27 @@ function FlyoutGroup({
/**
* The side-flyout content for one project: a search box over that project's
* worktrees + local branches, then the ordered list (main pinned, opened
- * worktrees by recency, create-on-demand branches last). Rendered as a
- * DropdownMenuSubContent — a real submenu, so it isn't clipped by the parent
- * menu's scroll container (Radix positions it fixed against the trigger).
+ * worktrees by recency, create-on-demand branches last).
+ *
+ * Rendered as a DropdownMenuSubContent wrapped in DropdownMenuPortal. shadcn's
+ * SubContent is NOT portaled by default (unlike DropdownMenuContent), so inline
+ * it renders as a descendant of the project menu's Popper wrapper. Radix
+ * positions that wrapper `position: fixed`, but the parent DropdownMenuContent's
+ * own Popper wrapper carries a `transform` — which makes it the containing block
+ * for the fixed SubContent — and both it and the recents list
+ * (`max-h-64 overflow-x-hidden` in ProjectSwitcher) have `overflow-x-hidden`. So
+ * the SubContent is clipped by that ancestor overflow rather than being placed
+ * fully on-screen: a w-96 flyout off a ~260px menu is visually cut off at the
+ * menu's right edge. Portaling it to the body removes those transform/overflow
+ * ancestors so the panel renders as an independent floating layer, unclipped. It
+ * always opens to the RIGHT and never flips left (`avoidCollisions={false}`); a
+ * small negative `sideOffset` overlaps the menu's right edge slightly so the
+ * panel stays visible near a narrow window's edge (see the props below). The
+ * submenu stays anchored to its trigger, and the parent still force-closes it on
+ * scroll via the hoisted flyout state (see ProjectSwitcher) — that path is
+ * independent of where the content mounts, and Radix still only mounts the
+ * content while the sub is open, so the focus-into-search effect below fires
+ * unchanged.
*/
function WorktreeFlyout({
group,
@@ -447,8 +466,10 @@ function WorktreeFlyout({
// from the open transition instead. The content — and this input — only mounts
// while open, so searchRef is live by the time this runs, and it lands after
// Radix's own focus so the input wins. `preventScroll` so focusing the input
- // can't nudge the parent recents scroll container, whose onScroll close would
- // otherwise self-dismiss the flyout the instant it opens.
+ // can't scroll any ancestor into view — now that the content is portaled the
+ // input no longer lives inside the recents scroll container, but the guard
+ // stays as defense in depth against a focus-driven scroll re-triggering the
+ // parent's onScroll close.
useEffect(() => {
if (open) searchRef.current?.focus({ preventScroll: true });
}, [open]);
@@ -508,114 +529,129 @@ function WorktreeFlyout({
const canCreate = isCurrentProject && typedName.length > 0;
return (
- <DropdownMenuSubContent
- sideOffset={4}
- className="flex max-h-80 w-96 flex-col gap-1 overflow-hidden p-1"
- data-testid={`project-switcher-flyout-${group.project.path}`}
- >
- <InputGroup className="mb-1 h-8 shrink-0">
- {/* Search magnifier leads so the row reads as a typeable field; the
+ <DropdownMenuPortal>
+ <DropdownMenuSubContent
+ // Independent floating panel: always opens to the RIGHT of the project
+ // menu and never flips left. SubContent already hardcodes side="right"
+ // (for LTR) internally — Radix sets it AFTER spreading our props, so a
+ // `side` prop here would be silently ignored; what actually pins it right
+ // is disabling Popper's collision logic. avoidCollisions={false} turns off
+ // both the flip and the shift, so no window edge can send it left.
+ avoidCollisions={false}
+ // With collisions off, nothing shifts the panel to keep it on-screen, so
+ // it opens flush-right of the ~260px menu; the anchor sits at the left of
+ // the navigator (min width 640px), leaving room for the w-96 panel. This
+ // small negative offset just pulls it a few px LEFT so it overlaps the
+ // menu's right edge slightly rather than floating detached — the
+ // maintainer OK'd a slight overlap since it's an independent panel.
+ sideOffset={-8}
+ className="flex max-h-80 w-96 flex-col gap-1 overflow-hidden p-1"
+ data-testid={`project-switcher-flyout-${group.project.path}`}
+ >
+ <InputGroup className="mb-1 h-8 shrink-0">
+ {/* Search magnifier leads so the row reads as a typeable field; the
default InputGroup border + focus ring (restored by dropping the
border-0 / ring-0 overrides) is what signals "you can type here". */}
- <InputGroupAddon align="inline-start">
- <Search aria-hidden="true" />
- </InputGroupAddon>
- <InputGroupInput
- ref={searchRef}
- aria-label={t`Search worktrees and branches`}
- placeholder={t`Search worktrees`}
- value={flyoutQuery}
- onChange={(e) => setFlyoutQuery(e.target.value)}
- // ArrowDown steps from the search box into the entry list (focus the
- // first row); typing still filters. Intercept BEFORE stopPropagation —
- // the stop keeps the enclosing submenu's typeahead/roving from stealing
- // the keys, but would also swallow ArrowDown, so nav has to run first.
- // Escape still closes (Radix's document-level dismiss ignores React
- // stopPropagation); ArrowLeft stays a cursor move inside the input.
- onKeyDown={(e) => {
- if (e.key === 'ArrowDown') {
- e.preventDefault();
- focusRowAt(0);
- }
- e.stopPropagation();
- }}
- data-testid={`project-switcher-flyout-search-${group.project.path}`}
- />
- </InputGroup>
- <div
- ref={listRef}
- className="min-h-0 flex-1 overflow-x-hidden overflow-y-auto overscroll-contain subtle-scrollbar"
- >
- {visible.length === 0 ? (
- <>
- <DropdownMenuLabel
- className="font-normal text-muted-foreground text-xs"
- role="status"
- aria-live="polite"
- >
- {t`No matching worktrees or branches.`}
- </DropdownMenuLabel>
- {/* No match, but a name was typed — offer to create a worktree with
+ <InputGroupAddon align="inline-start">
+ <Search aria-hidden="true" />
+ </InputGroupAddon>
+ <InputGroupInput
+ ref={searchRef}
+ aria-label={t`Search worktrees and branches`}
+ placeholder={t`Search worktrees`}
+ value={flyoutQuery}
+ onChange={(e) => setFlyoutQuery(e.target.value)}
+ // ArrowDown steps from the search box into the entry list (focus the
+ // first row); typing still filters. Intercept BEFORE stopPropagation —
+ // the stop keeps the enclosing submenu's typeahead/roving from stealing
+ // the keys, but would also swallow ArrowDown, so nav has to run first.
+ // Escape still closes (Radix's document-level dismiss ignores React
+ // stopPropagation); ArrowLeft stays a cursor move inside the input.
+ onKeyDown={(e) => {
+ if (e.key === 'ArrowDown') {
+ e.preventDefault();
+ focusRowAt(0);
+ }
+ e.stopPropagation();
+ }}
+ data-testid={`project-switcher-flyout-search-${group.project.path}`}
+ />
+ </InputGroup>
+ <div
+ ref={listRef}
+ className="min-h-0 flex-1 overflow-x-hidden overflow-y-auto overscroll-contain subtle-scrollbar"
+ >
+ {visible.length === 0 ? (
+ <>
+ <DropdownMenuLabel
+ className="font-normal text-muted-foreground text-xs"
+ role="status"
+ aria-live="polite"
+ >
+ {t`No matching worktrees or branches.`}
+ </DropdownMenuLabel>
+ {/* No match, but a name was typed — offer to create a worktree with
it. Only for the current project (creation anchors to the current
window). Closes the switcher + opens the pre-filled dialog. */}
- {canCreate ? (
- <DropdownMenuItem
- onSelect={(e) => {
- if (guardStaleSelect(e)) return;
- openNewWorktreeWith(typedName);
- }}
- onKeyDown={(e) => onRowKeyDown(e, () => openNewWorktreeWith(typedName))}
- className="flex items-center gap-2"
- data-testid="project-switcher-flyout-create"
- >
- <Plus aria-hidden="true" className="size-3.5 shrink-0" />
- <span className="min-w-0 flex-1 truncate text-sm" title={typedName}>
- <Trans>
- Create worktree{' '}
- <span className="font-medium">
- “<span className="font-mono">{typedName}</span>”
- </span>
- </Trans>
- </span>
- </DropdownMenuItem>
- ) : null}
- </>
- ) : (
- visible.map((entry) => {
- const key = entry.path ?? `branch:${entry.branch}`;
- const label = entry.branch ?? t`(detached)`;
- return (
- <DropdownMenuItem
- key={key}
- onSelect={(e) => {
- if (guardStaleSelect(e)) return;
- onPickFlyoutEntry(entry);
- }}
- onKeyDown={(e) => onRowKeyDown(e, () => onPickFlyoutEntry(entry))}
- className="flex items-center gap-2"
- data-testid={`project-switcher-flyout-entry-${key}`}
- data-current={entry.isCurrent ? 'true' : undefined}
- >
- <span className="min-w-0 flex-1 truncate text-sm" title={label}>
- {label}
- </span>
- {entry.isMain ? (
- <span className="shrink-0 text-muted-foreground text-xs">{t`default`}</span>
- ) : !entry.opened ? (
- <span
- className="shrink-0 text-muted-foreground text-xs"
- title={t`Create a worktree from this branch`}
- >
- {t`create worktree`}
+ {canCreate ? (
+ <DropdownMenuItem
+ onSelect={(e) => {
+ if (guardStaleSelect(e)) return;
+ openNewWorktreeWith(typedName);
+ }}
+ onKeyDown={(e) => onRowKeyDown(e, () => openNewWorktreeWith(typedName))}
+ className="flex items-center gap-2"
+ data-testid="project-switcher-flyout-create"
+ >
+ <Plus aria-hidden="true" className="size-3.5 shrink-0" />
+ <span className="min-w-0 flex-1 truncate text-sm" title={typedName}>
+ <Trans>
+ Create worktree{' '}
+ <span className="font-medium">
+ “<span className="font-mono">{typedName}</span>”
+ </span>
+ </Trans>
+ </span>
+ </DropdownMenuItem>
+ ) : null}
+ </>
+ ) : (
+ visible.map((entry) => {
+ const key = entry.path ?? `branch:${entry.branch}`;
+ const label = entry.branch ?? t`(detached)`;
+ return (
+ <DropdownMenuItem
+ key={key}
+ onSelect={(e) => {
+ if (guardStaleSelect(e)) return;
+ onPickFlyoutEntry(entry);
+ }}
+ onKeyDown={(e) => onRowKeyDown(e, () => onPickFlyoutEntry(entry))}
+ className="flex items-center gap-2"
+ data-testid={`project-switcher-flyout-entry-${key}`}
+ data-current={entry.isCurrent ? 'true' : undefined}
+ >
+ <span className="min-w-0 flex-1 truncate text-sm" title={label}>
+ {label}
</span>
- ) : null}
- {entry.isCurrent ? <CurrentCheck /> : null}
- </DropdownMenuItem>
- );
- })
- )}
- </div>
- </DropdownMenuSubContent>
+ {entry.isMain ? (
+ <span className="shrink-0 text-muted-foreground text-xs">{t`default`}</span>
+ ) : !entry.opened ? (
+ <span
+ className="shrink-0 text-muted-foreground text-xs"
+ title={t`Create a worktree from this branch`}
+ >
+ {t`create worktree`}
+ </span>
+ ) : null}
+ {entry.isCurrent ? <CurrentCheck /> : null}
+ </DropdownMenuItem>
+ );
+ })
+ )}
+ </div>
+ </DropdownMenuSubContent>
+ </DropdownMenuPortal>
);
}
diff --git a/packages/core/src/bridge/bind-frontmatter-doc.ts b/packages/core/src/bridge/bind-frontmatter-doc.ts
index 8f9d95287..c014b1413 100644
--- a/packages/core/src/bridge/bind-frontmatter-doc.ts
+++ b/packages/core/src/bridge/bind-frontmatter-doc.ts
@@ -1,4 +1,3 @@
-
import type * as Y from 'yjs';
import type { Err, Ok, Result } from '../config/result.ts';
import { type FrontmatterValidationError, toFrontmatterIssue } from '../frontmatter/errors.ts';
diff --git a/packages/core/src/bridge/bridge-invariant.ts b/packages/core/src/bridge/bridge-invariant.ts
index 8bfdb40cd..005627195 100644
--- a/packages/core/src/bridge/bridge-invariant.ts
+++ b/packages/core/src/bridge/bridge-invariant.ts
@@ -1,4 +1,3 @@
-
import { fnv1aDigest } from './hash-util.ts';
export type BridgeInvariantSite = 'observer-b' | 'persistence' | 'test-harness';
diff --git a/packages/core/src/bridge/doc-boundary-space.ts b/packages/core/src/bridge/doc-boundary-space.ts
index c18c086d5..8890f6739 100644
--- a/packages/core/src/bridge/doc-boundary-space.ts
+++ b/packages/core/src/bridge/doc-boundary-space.ts
@@ -1,4 +1,3 @@
-
import { FRONTMATTER_RE, stripFrontmatter } from '../extensions/frontmatter.ts';
const LEADING_BOUNDARY_RE = /^(?:\r?\n)+/;
diff --git a/packages/core/src/bridge/merge-three-way.ts b/packages/core/src/bridge/merge-three-way.ts
index 864bc7245..b0a80fbd9 100644
--- a/packages/core/src/bridge/merge-three-way.ts
+++ b/packages/core/src/bridge/merge-three-way.ts
@@ -37,7 +37,6 @@ function mergeThreeWayImpl(baseline: string, userText: string, agentText: string
return parts.join('\n');
}
-
export type BridgeMergeContentLossSide = 'user' | 'agent';
export type BridgeMergeContentLossWhich = 'substring' | 'order';
diff --git a/packages/core/src/bridge/normalize.ts b/packages/core/src/bridge/normalize.ts
index 592f0b956..e67f33b40 100644
--- a/packages/core/src/bridge/normalize.ts
+++ b/packages/core/src/bridge/normalize.ts
@@ -1,4 +1,3 @@
-
const COMMONMARK_ESCAPE_RE = /\\([!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~])/g;
const TABLE_ALIGN_ROW_RE = /^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)+\|?\s*$/;
diff --git a/packages/core/src/bridge/pm-structural-equivalence.ts b/packages/core/src/bridge/pm-structural-equivalence.ts
index 0be5203e4..754dc5cc2 100644
--- a/packages/core/src/bridge/pm-structural-equivalence.ts
+++ b/packages/core/src/bridge/pm-structural-equivalence.ts
@@ -32,7 +32,6 @@ const BR_SENTINEL: PmStructuralNode = { type: '__br__' };
const BR_LITERAL_RE = /^<br\s*\/?>$/i;
-
interface DegradeEntry {
readonly label: string;
readonly severity: ToleranceClassSeverity;
@@ -128,7 +127,6 @@ export interface ComparePmStructuralOptions {
ignoreAttrs?: (attrKey: string) => boolean;
}
-
/** Rebuild a node with `fn` applied to each child; identity when childless.
* Shared by the degrade canonicalizers so none re-implements the walk. */
function mapChildren(
@@ -250,7 +248,6 @@ function applyDegrades(tree: PmStructuralNode): {
return { normalized: current, fired };
}
-
export function comparePmStructural(
expected: PmStructuralNode,
actual: PmStructuralNode,
diff --git a/packages/core/src/bridge/subsequence.ts b/packages/core/src/bridge/subsequence.ts
index dca644141..af20de1e2 100644
--- a/packages/core/src/bridge/subsequence.ts
+++ b/packages/core/src/bridge/subsequence.ts
@@ -1,4 +1,3 @@
-
/** True when `needle` is a subsequence of `haystack` (two-pointer, O(n+m)):
* insertions in `haystack` are free; any dropped or substituted `needle` byte
* fails. */
diff --git a/packages/core/src/markdown/callout-transformer.ts b/packages/core/src/markdown/callout-transformer.ts
index a363dfd54..83d47404a 100644
--- a/packages/core/src/markdown/callout-transformer.ts
+++ b/packages/core/src/markdown/callout-transformer.ts
@@ -1,4 +1,3 @@
-
import type { Blockquote, Paragraph, Root } from 'mdast';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/comment-promoter.ts b/packages/core/src/markdown/comment-promoter.ts
index 47f0d07e4..193e286b0 100644
--- a/packages/core/src/markdown/comment-promoter.ts
+++ b/packages/core/src/markdown/comment-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Paragraph, PhrasingContent, Root, RootContent, Text } from 'mdast';
import { SKIP, visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/dedent-block-jsx-close.ts b/packages/core/src/markdown/dedent-block-jsx-close.ts
index b6299a948..ece5c02a1 100644
--- a/packages/core/src/markdown/dedent-block-jsx-close.ts
+++ b/packages/core/src/markdown/dedent-block-jsx-close.ts
@@ -1,4 +1,3 @@
-
import { findFencedRegions, isInsideFence } from './fence-regions.ts';
const INDENTED_BLOCK_JSX_CLOSE_RE = /^([ ]{1,3})(<\/[A-Z][A-Za-z0-9_]*\s*>)([ \t]*)$/gm;
diff --git a/packages/core/src/markdown/details-accordion-promoter.ts b/packages/core/src/markdown/details-accordion-promoter.ts
index acd398aa6..54774764a 100644
--- a/packages/core/src/markdown/details-accordion-promoter.ts
+++ b/packages/core/src/markdown/details-accordion-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Paragraph, Parent, Root, Text } from 'mdast';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/fence-regions.ts b/packages/core/src/markdown/fence-regions.ts
index fb5ac8e8a..c7518d614 100644
--- a/packages/core/src/markdown/fence-regions.ts
+++ b/packages/core/src/markdown/fence-regions.ts
@@ -1,4 +1,3 @@
-
const FENCE_RE = /^(`{3,}|~{3,})/gm;
export function findFencedRegions(src: string): Array<[number, number]> {
diff --git a/packages/core/src/markdown/fixtures/index.ts b/packages/core/src/markdown/fixtures/index.ts
index 6931623c7..00f5771ee 100644
--- a/packages/core/src/markdown/fixtures/index.ts
+++ b/packages/core/src/markdown/fixtures/index.ts
@@ -1,4 +1,3 @@
-
import { readFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -9,7 +8,6 @@ function fixturePath(...segments: string[]): string {
return resolve(FIXTURES_DIR, ...segments);
}
-
interface GfmExample {
section: string;
markdown: string;
@@ -19,7 +17,6 @@ export function loadGfmExamples(): GfmExample[] {
return JSON.parse(readFileSync(fixturePath('gfm', 'examples.json'), 'utf8')) as GfmExample[];
}
-
interface MdxCrashEntry {
id: string;
input: string;
@@ -71,7 +68,6 @@ export function loadLargeEmbedFixtures(): LargeEmbedFixture[] {
) as LargeEmbedFixture[];
}
-
export function loadPrd6955Before(): string {
return readFileSync(fixturePath('regression', 'prd-6955-before.md'), 'utf8');
}
@@ -80,7 +76,6 @@ export function loadPrd6955CorruptedTriplicated(): string {
return readFileSync(fixturePath('regression', 'prd-6955-corrupted-triplicated.md'), 'utf8');
}
-
export interface NgPinnedCase {
id: string;
name: string;
@@ -97,7 +92,6 @@ export function loadNgPinnedCases(): NgPinnedCase[] {
) as NgPinnedCase[];
}
-
export function loadLargeRealistic(): string {
return readFileSync(fixturePath('perf', 'large-realistic.md'), 'utf8');
}
diff --git a/packages/core/src/markdown/fixtures/perf/generate.ts b/packages/core/src/markdown/fixtures/perf/generate.ts
index daa3ef82b..8b1eb8519 100644
--- a/packages/core/src/markdown/fixtures/perf/generate.ts
+++ b/packages/core/src/markdown/fixtures/perf/generate.ts
@@ -1,4 +1,3 @@
-
import { writeFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -11,7 +10,6 @@ const BASELINE_ONLY_COUNTS = [500, 2500] as const;
const SEED = 0xf1de1117;
-
function mulberry32(seed: number): () => number {
let a = seed >>> 0;
return () => {
@@ -38,7 +36,6 @@ function pickWeighted<T>(rand: () => number, items: readonly [T, number][]): T {
return items[items.length - 1][0];
}
-
const WORDS = [
'lorem',
'ipsum',
@@ -156,7 +153,6 @@ function mdxBlock(rand: () => number): string {
return `<${name}>\n\n${sentence(rand)}\n\n</${name}>`;
}
-
type BlockKind = 'paragraph' | 'heading' | 'list' | 'code' | 'table' | 'mdx';
const MIX: readonly [BlockKind, number][] = [
@@ -195,7 +191,6 @@ function generateDocument(blockCount: number, seed: number): string {
return `${blocks.join('\n\n')}\n`;
}
-
function main(): void {
for (const count of [...BLOCK_COUNTS, ...BASELINE_ONLY_COUNTS]) {
const doc = generateDocument(count, SEED);
diff --git a/packages/core/src/markdown/guard-flanking-matrix.ts b/packages/core/src/markdown/guard-flanking-matrix.ts
index 32c055c5b..420dc0fe5 100644
--- a/packages/core/src/markdown/guard-flanking-matrix.ts
+++ b/packages/core/src/markdown/guard-flanking-matrix.ts
@@ -7,7 +7,6 @@ import {
import { BACKSLASH_GUARD_SUBSTITUTIONS, encodeBackslashEscapes } from './backslash-escape-guard.ts';
import { ENTITY_REF_GUARD_SUBSTITUTIONS, encodeEntityRefs } from './entity-ref-guard.ts';
-
export const ATTENTION_DELIMITERS = ['*', '_', '**', '~~', '=='] as const;
export type FlankClass = 'whitespace' | 'punctuation' | 'other';
diff --git a/packages/core/src/markdown/handler-shadow-audit.ts b/packages/core/src/markdown/handler-shadow-audit.ts
index 283913255..2653473da 100644
--- a/packages/core/src/markdown/handler-shadow-audit.ts
+++ b/packages/core/src/markdown/handler-shadow-audit.ts
@@ -1,4 +1,3 @@
-
export interface HandlerShadowWitness {
input: string;
expect: 'byte' | 'byte-and-reparse-type';
diff --git a/packages/core/src/markdown/highlight-promoter.ts b/packages/core/src/markdown/highlight-promoter.ts
index 7a22e8016..f758cf737 100644
--- a/packages/core/src/markdown/highlight-promoter.ts
+++ b/packages/core/src/markdown/highlight-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Parent, PhrasingContent, Root, Text } from 'mdast';
import type { MdxJsxTextElement } from 'mdast-util-mdx';
import { SKIP, visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/html-to-mdast.ts b/packages/core/src/markdown/html-to-mdast.ts
index 2f082e6d0..78fdfeb02 100644
--- a/packages/core/src/markdown/html-to-mdast.ts
+++ b/packages/core/src/markdown/html-to-mdast.ts
@@ -1,4 +1,3 @@
-
import type { Root as HastRoot } from 'hast';
import type { Root as MdastRoot } from 'mdast';
import rehypeParse from 'rehype-parse';
@@ -76,8 +75,7 @@ export function htmlToMdast(html: string, options?: HtmlToMdastOptions): MdastRo
throw new HtmlPayloadTooLargeError(html.length, maxBytes);
}
- const processor = unified()
- .use(rehypeParse, { fragment: true });
+ const processor = unified().use(rehypeParse, { fragment: true });
for (const plugin of cleanupPlugins) {
processor.use(plugin);
diff --git a/packages/core/src/markdown/image-promoter.ts b/packages/core/src/markdown/image-promoter.ts
index 994eb6917..706fa9afb 100644
--- a/packages/core/src/markdown/image-promoter.ts
+++ b/packages/core/src/markdown/image-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Image, Paragraph, Root } from 'mdast';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/index.ts b/packages/core/src/markdown/index.ts
index c58d0847d..58be35302 100644
--- a/packages/core/src/markdown/index.ts
+++ b/packages/core/src/markdown/index.ts
@@ -1,4 +1,3 @@
-
import {
type FromProseMirrorOptions,
fromPmMark,
@@ -197,7 +196,6 @@ export class MarkdownManager {
}
}
-
const registry = createRegistry();
function destructureAttrs(
@@ -246,7 +244,6 @@ function destructureAttrs(
return result;
}
-
function hasDirtyDescendant(node: PmNode): boolean {
let found = false;
node.descendants((child) => {
@@ -266,7 +263,6 @@ function effectiveDirty(node: PmNode, freshnessChecker?: StructuralFreshnessChec
return freshnessChecker ? freshnessChecker.isDiverged(node.toJSON()) : false;
}
-
function isEmptyMdastParagraph(node: MdastNodes): boolean {
if (node.type !== 'paragraph') return false;
const children = node.children ?? [];
@@ -335,7 +331,6 @@ function extractTextFromMdastNodes(nodes: MdastNodes[]): string {
return out;
}
-
import {
AUDIO_EXTENSIONS,
FILE_ATTACHMENT_EXTENSIONS,
@@ -585,7 +580,6 @@ function buildMdastToPmHandlers(
}));
}
-
if (m.emphasis) {
handlers.emphasis = toPmMark(m.emphasis, (node: Emphasis) => ({
sourceDelimiter: node.data?.sourceDelimiter ?? '*',
@@ -665,7 +659,6 @@ function buildMdastToPmHandlers(
}));
}
-
if (m.link) {
const sourceLiteralMark = m.sourceLiteral;
handlers.link = (node: Link, _parent: MdastParent, state: MdastToPmState) => {
@@ -944,7 +937,6 @@ function buildMdastToPmHandlers(
};
}
-
const blockUnknownHandler = (node: {
type: string;
position?: { start: { offset: number }; end: { offset: number } };
@@ -1070,7 +1062,6 @@ function buildMdastToPmHandlers(
return handlers as RemarkProseMirrorOptions['handlers'];
}
-
function buildPmToMdastHandlers(
schema: Schema,
freshness: FreshnessCheckerHolder,
diff --git a/packages/core/src/markdown/math-promoter.ts b/packages/core/src/markdown/math-promoter.ts
index bd79424c7..a5b511f25 100644
--- a/packages/core/src/markdown/math-promoter.ts
+++ b/packages/core/src/markdown/math-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Code, Root } from 'mdast';
import type { Math as MdastMath } from 'mdast-util-math';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
diff --git a/packages/core/src/markdown/mdast-to-hast-handlers.ts b/packages/core/src/markdown/mdast-to-hast-handlers.ts
index f84967798..679c72ef7 100644
--- a/packages/core/src/markdown/mdast-to-hast-handlers.ts
+++ b/packages/core/src/markdown/mdast-to-hast-handlers.ts
@@ -1,4 +1,3 @@
-
import type { Comment, Element, ElementContent, Properties } from 'hast';
import type { FootnoteDefinition, FootnoteReference } from 'mdast';
import type { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx';
diff --git a/packages/core/src/markdown/mdast-to-html.ts b/packages/core/src/markdown/mdast-to-html.ts
index df788a80d..8ce2b2492 100644
--- a/packages/core/src/markdown/mdast-to-html.ts
+++ b/packages/core/src/markdown/mdast-to-html.ts
@@ -1,4 +1,3 @@
-
import type { Element, Root as HastRoot, Text as HastText } from 'hast';
import type { Root as MdastRoot, Text as MdastText } from 'mdast';
import type { Handler } from 'mdast-util-to-hast';
diff --git a/packages/core/src/markdown/merged-walker.ts b/packages/core/src/markdown/merged-walker.ts
index a58f8c720..35d74b85e 100644
--- a/packages/core/src/markdown/merged-walker.ts
+++ b/packages/core/src/markdown/merged-walker.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Parent, Root } from 'mdast';
import { SKIP, visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/mermaid-promoter.ts b/packages/core/src/markdown/mermaid-promoter.ts
index 17ed2b829..1a897fca8 100644
--- a/packages/core/src/markdown/mermaid-promoter.ts
+++ b/packages/core/src/markdown/mermaid-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Code, Root } from 'mdast';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/parse-with-fallback.ts b/packages/core/src/markdown/parse-with-fallback.ts
index 7e4a9a48b..9864b3b60 100644
--- a/packages/core/src/markdown/parse-with-fallback.ts
+++ b/packages/core/src/markdown/parse-with-fallback.ts
@@ -168,7 +168,6 @@ export function parseRecursive(
}
}
-
interface VFilePlace {
offset?: number;
start?: { offset?: number };
@@ -187,7 +186,6 @@ function extractErrorOffset(err: unknown): number | undefined {
return undefined;
}
-
interface Region {
start: number;
end: number;
@@ -211,7 +209,6 @@ function nearestBlankLineAfter(src: string, offset: number): number | null {
return null;
}
-
export interface TagEvent {
kind: 'open' | 'close' | 'self-close';
name: string;
@@ -358,7 +355,6 @@ function findFallbackRegion(src: string, errorOffset: number): Region {
return { start: blockStart, end: blockEnd };
}
-
interface SourceBlock {
src: string;
start: number;
@@ -456,7 +452,6 @@ function tryPerBlockFallback(
};
}
-
function wholeDocRawText(source: string): JSONContent {
return {
type: 'doc',
diff --git a/packages/core/src/markdown/parser-drop-closure.ts b/packages/core/src/markdown/parser-drop-closure.ts
index 43d420187..e6ab4fd57 100644
--- a/packages/core/src/markdown/parser-drop-closure.ts
+++ b/packages/core/src/markdown/parser-drop-closure.ts
@@ -1,4 +1,3 @@
-
export type DroppedTokenAdjudication =
| {
kind: 'format-dof-axis';
diff --git a/packages/core/src/markdown/pipeline.ts b/packages/core/src/markdown/pipeline.ts
index 5b9550e90..5d6db7aa8 100644
--- a/packages/core/src/markdown/pipeline.ts
+++ b/packages/core/src/markdown/pipeline.ts
@@ -1,4 +1,3 @@
-
import {
type FromProseMirrorOptions,
fromProseMirror,
diff --git a/packages/core/src/markdown/position-aware-join.ts b/packages/core/src/markdown/position-aware-join.ts
index 4ac5731e7..248685cfe 100644
--- a/packages/core/src/markdown/position-aware-join.ts
+++ b/packages/core/src/markdown/position-aware-join.ts
@@ -1,4 +1,3 @@
-
import type { Join } from 'mdast-util-to-markdown';
import type { Position } from 'unist';
diff --git a/packages/core/src/markdown/position-slice.ts b/packages/core/src/markdown/position-slice.ts
index 240be90e6..50a193a16 100644
--- a/packages/core/src/markdown/position-slice.ts
+++ b/packages/core/src/markdown/position-slice.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Root } from 'mdast';
import { visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
@@ -467,8 +466,7 @@ export function applyPositionSliceToNode(
const first = source[startOff];
if (first !== '[' && first !== '<' && !node.title) {
node.data.sourceStyle = 'gfm-autolink';
- }
- else if (first === '[') {
+ } else if (first === '[') {
const slice = source.slice(startOff, endOff);
const closeBracketIdx = slice.lastIndexOf('](');
if (closeBracketIdx !== -1) {
diff --git a/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts b/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts
index ca225ce9b..db10fa54b 100644
--- a/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts
+++ b/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts
@@ -1,4 +1,3 @@
-
import type { Comment, Element, Root, Text } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts b/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts
index 3a2524a9a..34068d103 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts
@@ -1,4 +1,3 @@
-
import type { Element, ElementContent, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts b/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts
index 2279a0189..93151d43b 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts
@@ -1,4 +1,3 @@
-
import type { Element, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts b/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts
index a0f467c42..188f02d83 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts
@@ -1,4 +1,3 @@
-
import type { Element, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts b/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts
index 4e8542a21..4ba2c3418 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts
@@ -1,4 +1,3 @@
-
import type { Element, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts b/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts
index a3c96b24a..1a74b1272 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts
@@ -1,4 +1,3 @@
-
import type { Element, ElementContent, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts b/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts
index e95cf43d6..de35e7b79 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts
@@ -1,4 +1,3 @@
-
import type { Comment, Element, ElementContent, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts b/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts
index ffdb4d5b5..b4be1b2ea 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts
@@ -1,4 +1,3 @@
-
import type { Element, ElementContent, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts b/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts
index e2a96d1a7..3c8d88b7c 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts
@@ -1,4 +1,3 @@
-
import type { Element, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/resolve-image-url.ts b/packages/core/src/markdown/resolve-image-url.ts
index 0389575ac..cf2c9da8e 100644
--- a/packages/core/src/markdown/resolve-image-url.ts
+++ b/packages/core/src/markdown/resolve-image-url.ts
@@ -1,4 +1,3 @@
-
import { isRelativeUrl } from './safe-url.ts';
function isDevDiagnosticContext(): boolean {
diff --git a/packages/core/src/markdown/safe-url.ts b/packages/core/src/markdown/safe-url.ts
index 8be632ba4..4d3250d3a 100644
--- a/packages/core/src/markdown/safe-url.ts
+++ b/packages/core/src/markdown/safe-url.ts
@@ -1,4 +1,3 @@
-
export const SAFE_URL_SCHEMES = ['https', 'http', 'mailto', 'tel', 'ftp', 'sms'] as const;
const SCHEME_ALT = SAFE_URL_SCHEMES.map((s) => `${s}:`).join('|');
diff --git a/packages/core/src/markdown/serialize-helpers.ts b/packages/core/src/markdown/serialize-helpers.ts
index 542204403..46cc6a074 100644
--- a/packages/core/src/markdown/serialize-helpers.ts
+++ b/packages/core/src/markdown/serialize-helpers.ts
@@ -1,4 +1,3 @@
-
import type { Node as PmNode } from '@tiptap/pm/model';
import type { MdxJsxAttribute, MdxJsxExpressionAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import type { PropDef, SerializeContext } from '../registry/types.ts';
diff --git a/packages/core/src/markdown/single-dollar-math-promoter.ts b/packages/core/src/markdown/single-dollar-math-promoter.ts
index fe73659e6..be97d4d62 100644
--- a/packages/core/src/markdown/single-dollar-math-promoter.ts
+++ b/packages/core/src/markdown/single-dollar-math-promoter.ts
@@ -1,4 +1,3 @@
-
import type { PhrasingContent, Root, Text } from 'mdast';
import type { InlineMath } from 'mdast-util-math';
import { SKIP, visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/to-markdown-handlers.ts b/packages/core/src/markdown/to-markdown-handlers.ts
index e1161455b..1a2fb5d50 100644
--- a/packages/core/src/markdown/to-markdown-handlers.ts
+++ b/packages/core/src/markdown/to-markdown-handlers.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Parents } from 'mdast';
import type { MdxJsxAttribute, MdxJsxExpressionAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import type { Handle, Info, State } from 'mdast-util-to-markdown';
diff --git a/packages/core/src/markdown/unknown-mdast-guard.ts b/packages/core/src/markdown/unknown-mdast-guard.ts
index c5bfd2386..cd245c38c 100644
--- a/packages/core/src/markdown/unknown-mdast-guard.ts
+++ b/packages/core/src/markdown/unknown-mdast-guard.ts
@@ -1,4 +1,3 @@
-
import type { Root as MdastRoot } from 'mdast';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/whitespace-char-ref.ts b/packages/core/src/markdown/whitespace-char-ref.ts
index 1b75ba564..a100cad76 100644
--- a/packages/core/src/markdown/whitespace-char-ref.ts
+++ b/packages/core/src/markdown/whitespace-char-ref.ts
@@ -1,4 +1,3 @@
-
const INLINE_WHITESPACE_BY_CODE: ReadonlyMap<number, string> = new Map([
[0x20, ' '],
[0x09, '\t'],
diff --git a/packages/core/src/markdown/wiki-link-micromark.ts b/packages/core/src/markdown/wiki-link-micromark.ts
index afd9936fe..6dad26200 100644
--- a/packages/core/src/markdown/wiki-link-micromark.ts
+++ b/packages/core/src/markdown/wiki-link-micromark.ts
@@ -17,7 +17,6 @@ declare module 'micromark-util-types' {
}
}
-
const CODE_BANG = 33; // !
const CODE_LBRACKET = 91; // [
const CODE_RBRACKET = 93; // ]
@@ -261,7 +260,6 @@ export function wikiLinkSyntax(): Extension {
};
}
-
function enterWikiLink(this: CompileContext, token: Token) {
this.enter(
{
@@ -387,7 +385,6 @@ export const wikiLinkToMarkdown: {
unsafe: [{ character: '[', inConstruct: ['phrasing'] }],
};
-
const MICROMARK_EXT = wikiLinkSyntax();
export function remarkWikiLink(this: Processor) {