Skip to content
Closed
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
8 changes: 4 additions & 4 deletions apps/web/src/components/file-viewer/FileEditorPane.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Editable surface for the file viewer's edit mode.
*
* Wraps a `contentEditable` pierre File in an `EditorProvider`. The attach is
* Wraps a `contentEditable` pierre File in an `EditProvider`. The attach is
* deferred to a post-mount effect: attaching during mount is unsafe under
* StrictMode (the doubled mount effect runs edit → cleanUp → edit and
* pierre's re-attach render sync short-circuits on cached content, leaving
Expand All @@ -18,7 +18,7 @@
import { useEffect, useMemo, useRef, useState } from "react";
import { useQueryClient } from "@tanstack/react-query";
import { Editor } from "@pierre/diffs/editor";
import { EditorProvider, File as PierreFile } from "@pierre/diffs/react";
import { EditProvider, File as PierreFile } from "@pierre/diffs/react";

import { useFileViewerStore, type FileViewerContext } from "../../fileViewerStore";
import { useTheme } from "../../hooks/useTheme";
Expand Down Expand Up @@ -134,7 +134,7 @@ export function FileEditorPane({
);

return (
<EditorProvider editor={editor}>
<EditProvider editor={editor}>
<PierreFile
file={{
name: path,
Expand All @@ -151,6 +151,6 @@ export function FileEditorPane({
disableWorkerPool
options={pierreOptions}
/>
</EditorProvider>
</EditProvider>
);
}
28 changes: 14 additions & 14 deletions apps/web/src/components/file-viewer/FileViewerPierre.browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import type { SelectedLineRange } from "@pierre/diffs";
import { getFiletypeFromFileName, preloadHighlighter } from "@pierre/diffs";
import { Editor } from "@pierre/diffs/editor";
import { EditorProvider, File as PierreFile } from "@pierre/diffs/react";
import { EditProvider, File as PierreFile } from "@pierre/diffs/react";

import { DIFF_PANEL_UNSAFE_CSS } from "../DiffPanel.styles";
import { DiffWorkerPoolProvider } from "../DiffWorkerPoolProvider";
Expand Down Expand Up @@ -218,7 +218,7 @@
});
});

// Mirrors the editable-file wiring (EditorProvider + contentEditable File) so
// Mirrors the editable-file wiring (EditProvider + contentEditable File) so
// editor attachment regressions surface here instead of in the app.
function EditableHarness({
path,
Expand All @@ -231,7 +231,7 @@
}) {
return (
<DiffWorkerPoolProvider>
<EditorProvider editor={editor}>
<EditProvider editor={editor}>
<div style={{ height: 300, overflow: "auto" }}>
<PierreFile
key={path}
Expand All @@ -245,7 +245,7 @@
}}
/>
</div>
</EditorProvider>
</EditProvider>
</DiffWorkerPoolProvider>
);
}
Expand All @@ -255,7 +255,7 @@
const deadline = performance.now() + timeoutMs;
const ready = () => {
try {
return editor.getState().file != null;
return typeof editor.getText() === "string";
} catch {
return false;
}
Expand Down Expand Up @@ -286,7 +286,7 @@
);
await waitForEditorDocument(editor);

editor.applyEdits(

Check failure on line 289 in apps/web/src/components/file-viewer/FileViewerPierre.browser.tsx

View workflow job for this annotation

GitHub Actions / Format, Lint, Typecheck, Test, Browser Test, Build

[chromium] src/components/file-viewer/FileViewerPierre.browser.tsx > FileViewer pierre editing > applies programmatic edits and reports changes with undo support

Error: Editor is not attached ❯ Editor.applyEdits ../../node_modules/.pnpm/@pierre+diffs@1.3.0-beta.10_@shikijs+themes@4.3.1_react-dom@19.2.7_react@19.2.7__react@19.2.7/node_modules/@pierre/diffs/dist/editor/editor.js:177:34 ❯ applyEdits src/components/file-viewer/FileViewerPierre.browser.tsx:289:11
[
{
range: { start: { line: 0, character: 6 }, end: { line: 0, character: 11 } },
Expand Down Expand Up @@ -326,7 +326,7 @@
// keystrokes are harmless — the assertion needs one to follow "start".
const deadline = performance.now() + 15_000;
while (changes.length === 0) {
editor.setSelections([

Check failure on line 329 in apps/web/src/components/file-viewer/FileViewerPierre.browser.tsx

View workflow job for this annotation

GitHub Actions / Format, Lint, Typecheck, Test, Browser Test, Build

[chromium] src/components/file-viewer/FileViewerPierre.browser.tsx > FileViewer pierre editing > accepts typed input through the contentEditable surface

Error: Text document is not initialized ❯ Editor.setSelections ../../node_modules/.pnpm/@pierre+diffs@1.3.0-beta.10_@shikijs+themes@4.3.1_react-dom@19.2.7_react@19.2.7__react@19.2.7/node_modules/@pierre/diffs/dist/editor/editor.js:247:37 ❯ setSelections src/components/file-viewer/FileViewerPierre.browser.tsx:329:13
{ start: { line: 0, character: 5 }, end: { line: 0, character: 5 }, direction: "none" },
]);
editor.focus();
Expand All @@ -350,7 +350,7 @@
function WrapHarness({ wrap }: { wrap: boolean }) {
return (
<DiffWorkerPoolProvider>
<EditorProvider editor={editor}>
<EditProvider editor={editor}>
<div style={{ height: 300, overflow: "auto" }}>
<PierreFile
file={{ name: "w2.ts", contents: "const w = 0;\n", cacheKey: "edit:w2.ts" }}
Expand All @@ -363,7 +363,7 @@
}}
/>
</div>
</EditorProvider>
</EditProvider>
</DiffWorkerPoolProvider>
);
}
Expand All @@ -371,7 +371,7 @@
const screen = await render(<WrapHarness wrap={false} />);
await waitForEditorDocument(editor);

editor.applyEdits(

Check failure on line 374 in apps/web/src/components/file-viewer/FileViewerPierre.browser.tsx

View workflow job for this annotation

GitHub Actions / Format, Lint, Typecheck, Test, Browser Test, Build

[chromium] src/components/file-viewer/FileViewerPierre.browser.tsx > FileViewer pierre editing > keeps the edited document across option-driven re-renders (word wrap)

Error: Editor is not attached ❯ Editor.applyEdits ../../node_modules/.pnpm/@pierre+diffs@1.3.0-beta.10_@shikijs+themes@4.3.1_react-dom@19.2.7_react@19.2.7__react@19.2.7/node_modules/@pierre/diffs/dist/editor/editor.js:177:34 ❯ applyEdits src/components/file-viewer/FileViewerPierre.browser.tsx:374:11
[
{
range: { start: { line: 0, character: 10 }, end: { line: 0, character: 11 } },
Expand All @@ -381,12 +381,12 @@
true,
);
await settle(100);
expect(editor.getState().file.contents).toContain("const w = 7;");
expect(editor.getText()).toContain("const w = 7;");

screen.rerender(<WrapHarness wrap={true} />);
await settle();

expect(editor.getState().file.contents).toContain("const w = 7;");
expect(editor.getText()).toContain("const w = 7;");
expect(editor.canUndo).toBe(true);

screen.unmount();
Expand All @@ -413,11 +413,11 @@
await waitForEditorDocument(editor);

const deadline = performance.now() + 15_000;
while (!editor.getState().file.contents.includes("start!") && performance.now() < deadline) {
while (!editor.getText().includes("start!") && performance.now() < deadline) {
await settle(150);
}

expect(editor.getState().file.contents).toContain("start!\nnext");
expect(editor.getText()).toContain("start!\nnext");
expect(editor.getState().selections?.[0]).toMatchObject({
start: { line: 0, character: 6 },
end: { line: 0, character: 6 },
Expand All @@ -443,7 +443,7 @@
editorRef = editor;
return (
<DiffWorkerPoolProvider>
<EditorProvider editor={editor}>
<EditProvider editor={editor}>
<div style={{ height: 300, overflow: "auto" }}>
<PierreFile
key={path}
Expand All @@ -452,7 +452,7 @@
options={{ disableFileHeader: true, theme: "pierre-dark", themeType: "dark" }}
/>
</div>
</EditorProvider>
</EditProvider>
</DiffWorkerPoolProvider>
);
}
Expand All @@ -467,7 +467,7 @@
const editor = editorRef as unknown as Editor<undefined>;
expect(editor).not.toBeNull();
await waitForEditorDocument(editor);
editor.applyEdits(

Check failure on line 470 in apps/web/src/components/file-viewer/FileViewerPierre.browser.tsx

View workflow job for this annotation

GitHub Actions / Format, Lint, Typecheck, Test, Browser Test, Build

[chromium] src/components/file-viewer/FileViewerPierre.browser.tsx > FileViewer pierre editing > survives StrictMode double-mounting with a deferred editor attach

Error: Editor is not attached ❯ Editor.applyEdits ../../node_modules/.pnpm/@pierre+diffs@1.3.0-beta.10_@shikijs+themes@4.3.1_react-dom@19.2.7_react@19.2.7__react@19.2.7/node_modules/@pierre/diffs/dist/editor/editor.js:177:34 ❯ applyEdits src/components/file-viewer/FileViewerPierre.browser.tsx:470:11
[
{
range: { start: { line: 0, character: 10 }, end: { line: 0, character: 11 } },
Expand All @@ -477,7 +477,7 @@
true,
);
await settle(100);
expect(editor.getState().file.contents).toContain("const s = 9;");
expect(editor.getText()).toContain("const s = 9;");

screen.unmount();
});
Expand Down
Loading
Loading