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
35 changes: 35 additions & 0 deletions apps/desktop/src/features/editor/Editor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,41 @@ describe("Editor", () => {
expect(screen.getAllByDisplayValue("Updated title")).toHaveLength(2);
});

it("allows inserting spaces while editing text properties", async () => {
setEditorTabs([
{
id: "tab-1",
noteId: "notes/current",
title: "Frontmatter title",
content: "---\ntitle: Frontmatter title\n---\nBody",
},
]);

renderComponent(<Editor />);

await act(async () => {
fireEvent.click(screen.getByRole("button", { name: "Properties" }));
});

const view = getEditorView();
const propertyInput = screen.getAllByDisplayValue(
"Frontmatter title",
)[1];

await act(async () => {
fireEvent.change(propertyInput, {
target: { value: "Frontmatter title " },
});
});

expect((propertyInput as HTMLInputElement).value).toBe(
"Frontmatter title ",
);
expect(view.state.doc.toString()).toContain(
'title: "Frontmatter title "',
);
});

it("does not underline markdown headings in source mode", async () => {
setEditorTabs([
{
Expand Down
14 changes: 14 additions & 0 deletions apps/desktop/src/features/editor/FrontmatterPanel.helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,18 @@ tags:
---
`);
});

it("preserves a trailing space while text properties are being edited", () => {
const raw = serializeFrontmatterRaw([
{ key: "title", value: "Roadmap " },
]);

expect(raw).toBe(`---
title: "Roadmap "
---
`);
expect(parseFrontmatterRaw(raw ?? "")).toEqual([
{ key: "title", value: "Roadmap " },
]);
});
});
16 changes: 11 additions & 5 deletions apps/desktop/src/features/editor/FrontmatterPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ export function serializeFrontmatterRaw(
key: key.trim(),
value: Array.isArray(value)
? value.map((item) => item.trim()).filter(Boolean)
: typeof value === "string"
? value.trim()
: value,
: value,
}))
.filter(({ key, value }) => {
if (!key) return false;
if (Array.isArray(value)) return value.length > 0;
return value !== null && value !== "";
return (
value !== null &&
(typeof value !== "string" || value.trim() !== "")
);
});

if (!cleaned.length) return null;
Expand All @@ -104,7 +105,12 @@ export function serializeFrontmatterRaw(

function quoteYaml(value: string): string {
if (!value) return '""';
if (/^[A-Za-z0-9 _./:@#%+,-]+$/.test(value)) return value;
if (
value.trim() === value &&
/^[A-Za-z0-9 _./:@#%+,-]+$/.test(value)
) {
return value;
}
return JSON.stringify(value);
}

Expand Down
Loading