Skip to content

Commit df508cd

Browse files
committed
fix(desktop): refresh restored tab editors
1 parent 6455555 commit df508cd

4 files changed

Lines changed: 49 additions & 1 deletion

File tree

apps/desktop/src/App.test.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,45 @@ describe("Markra workspace", () => {
300300
expect(mockedConsumeWelcomeDocumentState).not.toHaveBeenCalled();
301301
});
302302

303+
it("switches visual editor content after restoring multiple document tabs", async () => {
304+
const guidePath = "/mock-files/vault/guide.md";
305+
const notesPath = "/mock-files/vault/notes.md";
306+
mockedGetStoredWorkspaceState.mockResolvedValue({
307+
aiAgentSessionId: "session-restored-tabs",
308+
filePath: notesPath,
309+
fileTreeOpen: false,
310+
folderName: null,
311+
folderPath: null,
312+
openFilePaths: [guidePath, notesPath]
313+
});
314+
mockedReadNativeMarkdownFile.mockImplementation(async (path) => {
315+
if (path === guidePath) {
316+
return {
317+
content: "# Guide",
318+
name: "guide.md",
319+
path
320+
};
321+
}
322+
323+
return {
324+
content: "# Notes",
325+
name: "notes.md",
326+
path
327+
};
328+
});
329+
330+
renderApp();
331+
332+
expect(await screen.findByRole("heading", { name: "Notes" })).toBeInTheDocument();
333+
expect(screen.getByRole("tab", { name: /notes\.md/ })).toHaveAttribute("aria-selected", "true");
334+
335+
fireEvent.click(screen.getByRole("tab", { name: /guide\.md/ }));
336+
337+
expect(await screen.findByRole("heading", { name: "Guide" })).toBeInTheDocument();
338+
expect(screen.queryByRole("heading", { name: "Notes" })).not.toBeInTheDocument();
339+
expect(screen.getByRole("tab", { name: /guide\.md/ })).toHaveAttribute("aria-selected", "true");
340+
});
341+
303342
it("restores a saved side-by-side tab group on app launch", async () => {
304343
const firstPath = "/mock-files/vault/docs/1.md";
305344
const secondPath = "/mock-files/vault/docs/2.md";

apps/desktop/src/App.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,6 +2245,7 @@ export default function App() {
22452245
bodyFontSize={editorPreferences.preferences.bodyFontSize}
22462246
contentWidth={activeEditorContentWidth}
22472247
contentWidthPx={activeEditorContentWidthPx}
2248+
documentKey={activeTabId}
22482249
documentPath={document.path}
22492250
editorTheme={appTheme.editorTheme}
22502251
initialContent={document.content}
@@ -2325,6 +2326,7 @@ export default function App() {
23252326
bodyFontSize={editorPreferences.preferences.bodyFontSize}
23262327
contentWidth={activeEditorContentWidth}
23272328
contentWidthPx={activeEditorContentWidthPx}
2329+
documentKey={activeTabId}
23282330
documentPath={document.path}
23292331
editorTheme={appTheme.editorTheme}
23302332
initialContent={document.content}
@@ -2377,6 +2379,7 @@ export default function App() {
23772379
content={sideDocumentTab.content}
23782380
contentWidth={activeEditorContentWidth}
23792381
contentWidthPx={activeEditorContentWidthPx}
2382+
documentKey={sideDocumentTab.id}
23802383
documentPath={sideDocumentTab.path}
23812384
editorTheme={appTheme.editorTheme}
23822385
language={appLanguage.language}

apps/desktop/src/components/MarkdownPaper.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type MarkdownPaperProps = {
1818
contentWidthMax?: number;
1919
contentWidthMin?: number;
2020
contentWidthPx?: number | null;
21+
documentKey?: string | null;
2122
documentPath?: MarkdownPaperSurfaceProps["documentPath"];
2223
editorTheme?: EditorTheme;
2324
initialContent: string;
@@ -50,6 +51,7 @@ export function MarkdownPaper({
5051
contentWidthMax = editorCustomContentWidthMax,
5152
contentWidthMin = editorCustomContentWidthMin,
5253
contentWidthPx = null,
54+
documentKey,
5355
documentPath,
5456
editorTheme = "light",
5557
initialContent,
@@ -81,6 +83,7 @@ export function MarkdownPaper({
8183
...(bottomOverlayInset > 0 ? { paddingBottom: `${bottomOverlayInset}px` } : {})
8284
} satisfies CSSProperties;
8385
const topInsetClassName = topInset === "tabs" ? "pt-24 max-[900px]:pt-20" : "pt-14 max-[900px]:pt-10";
86+
const editorInstanceKey = `${documentKey ?? documentPath ?? "untitled"}:${revision}`;
8487

8588
return (
8689
<section
@@ -90,7 +93,7 @@ export function MarkdownPaper({
9093
ref={scrollRef}
9194
>
9295
<article
93-
key={revision}
96+
key={editorInstanceKey}
9497
className={`markdown-paper relative mx-auto min-h-screen w-full max-w-215 px-18 pb-30 ${topInsetClassName} text-[16px] leading-[1.65] text-(--text-primary) caret-(--accent) outline-none focus:outline-none max-[900px]:px-5.25`}
9598
style={paperStyle}
9699
aria-label={t(language, "app.markdownEditor")}

apps/desktop/src/components/SideDocumentPane.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type SideDocumentPaneProps = {
1111
content: string;
1212
contentWidth: EditorContentWidth;
1313
contentWidthPx: number | null;
14+
documentKey?: string | null;
1415
documentPath?: string | null;
1516
editorTheme: EditorTheme;
1617
language?: AppLanguage;
@@ -37,6 +38,7 @@ export function SideDocumentPane({
3738
content,
3839
contentWidth,
3940
contentWidthPx,
41+
documentKey,
4042
documentPath,
4143
editorTheme,
4244
language = "en",
@@ -81,6 +83,7 @@ export function SideDocumentPane({
8183
bodyFontSize={bodyFontSize}
8284
contentWidth={contentWidth}
8385
contentWidthPx={contentWidthPx}
86+
documentKey={documentKey}
8487
documentPath={documentPath}
8588
editorTheme={editorTheme}
8689
initialContent={content}

0 commit comments

Comments
 (0)