Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore(editor): add a Markdown mode corner label

boojackc2bab22460b5
diff --git a/web/src/components/MemoEditor/README.md b/web/src/components/MemoEditor/README.md
index 2f886f756..9c8a6b55e 100644
--- a/web/src/components/MemoEditor/README.md
+++ b/web/src/components/MemoEditor/README.md
@@ -47,7 +47,7 @@ A reducer (`edit/state/reducer.ts`) drives an external store; consumers subscrib
### Formatting and source mode
-Formatting is the editor's own: its toolbar appears over selected text, the slash menu and Markdown shortcuts change block types, and its keys cover the rest. The editor's `mode` option shows the whole memo as Markdown text, with its syntax highlighted, and edits it as text; `useSourceMode` remembers the choice per device. To people it is "Markdown mode", the + menu's item with the code glyph (Lucide `CodeXml`), checked while on; in code it keeps the editor's name, source mode. Nothing in the editor names the mode: the text shows it, as it does in Obsidian and GitLab, and the memo's chrome stays the memo's. Switching changes no text and emits no change. In source mode the toolbar, slash menu, block handle and link card do not show; the `#tag` and `:emoji` popups open as in rich mode, the formatting keys edit the Markdown, and the checklist chip toggles the task marker on the caret's line through the same `toggleTaskList` command. The controller reads tags and checklists from the text parsed as a memo. The source text is in the body font (the editor's `sourceFont` token is left at its default) so a switch keeps the text's rhythm; nothing in memos targets the editor's source classes.
+Formatting is the editor's own: its toolbar appears over selected text, the slash menu and Markdown shortcuts change block types, and its keys cover the rest. The editor's `mode` option shows the whole memo as Markdown text, with its syntax highlighted, and edits it as text; `useSourceMode` remembers the choice per device. To people it is "Markdown mode", the + menu's item with the code glyph (Lucide `CodeXml`), checked while on; in code it keeps the editor's name, source mode. A small, noninteractive `Markdown` label sits inside the composer's top-right corner while source mode is on. Switching changes no text and emits no change. In source mode the toolbar, slash menu, block handle and link card do not show; the `#tag` and `:emoji` popups open as in rich mode, the formatting keys edit the Markdown, and the checklist chip toggles the task marker on the caret's line through the same `toggleTaskList` command. The controller reads tags and checklists from the text parsed as a memo. The source text is in the body font (the editor's `sourceFont` token is left at its default) so a switch keeps the text's rhythm; nothing in memos targets the editor's source classes.
### Saving
diff --git a/web/src/components/MemoEditor/edit/EditSession.tsx b/web/src/components/MemoEditor/edit/EditSession.tsx
index 5404a2825..683cbcb9a 100644
--- a/web/src/components/MemoEditor/edit/EditSession.tsx
+++ b/web/src/components/MemoEditor/edit/EditSession.tsx
@@ -346,6 +346,17 @@ export const EditSession: React.FC<EditSessionProps> = ({
!isFocusMode && className,
)}
>
+ {isSourceMode && (
+ <span
+ className={cn(
+ "pointer-events-none absolute end-0 top-0 rounded-es-lg rounded-se-lg border-s border-b border-border/70 bg-muted/40 px-1.5 py-1 select-none font-mono text-[10px] font-medium leading-3 text-muted-foreground [text-box:trim-both_cap_alphabetic]",
+ isFocusMode && "border-border py-px leading-none",
+ )}
+ aria-label={t("editor.markdown-mode")}
+ >
+ Markdown
+ </span>
+ )}
{/* Formatting is the editor's own: its toolbar appears over selected
text, and the slash menu and Markdown shortcuts change block types.
Focus mode always shows the memo's time ("Now" before it has one) and adds
diff --git a/web/src/components/MemoEditor/edit/Toolbar/InsertMenu.tsx b/web/src/components/MemoEditor/edit/Toolbar/InsertMenu.tsx
index eca18746e..6476a497e 100644
--- a/web/src/components/MemoEditor/edit/Toolbar/InsertMenu.tsx
+++ b/web/src/components/MemoEditor/edit/Toolbar/InsertMenu.tsx
@@ -160,9 +160,8 @@ const InsertMenu = (props: InsertMenuProps) => {
))}
{/* How the composer presents itself. Focus mode is absent when a host owns the
editor's presentation; Markdown mode (the editor's source mode) only changes how
- the text is edited, so every composer has it. Checked while on: the text shows
- the mode, and nothing in the editor names it. The code glyph says this mode
- shows the markup. */}
+ the text is edited, so every composer has it. Checked while on, with a corner
+ label in the composer. The code glyph says this mode shows the markup. */}
<DropdownMenuSeparator />
{viewToggles && (
<DropdownMenuItem onClick={viewToggles.onToggleFocusMode}>
diff --git a/web/tests/memo-editor-source-mode.test.tsx b/web/tests/memo-editor-source-mode.test.tsx
index 302faaf0c..76cbf5e8f 100644
--- a/web/tests/memo-editor-source-mode.test.tsx
+++ b/web/tests/memo-editor-source-mode.test.tsx
@@ -60,23 +60,24 @@ afterEach(() => {
});
describe("MemoEditor source mode", () => {
- it("switches from the + menu and back, and nothing in the editor names the mode", () => {
+ it("shows the Markdown label only while source mode is on", () => {
const { container } = mount();
expect(sourceText(container)).toBeNull();
+ expect(screen.queryByText("Markdown", { exact: true })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "common.add" }));
fireEvent.click(screen.getByRole("menuitemcheckbox", { name: "editor.markdown-mode" }));
expect(sourceText(container)).not.toBeNull();
expect(localStorage.getItem(MODE_KEY)).toBe(JSON.stringify("source"));
- // The text shows the mode; the composer adds no tag or indicator for it.
- expect(screen.queryByRole("button", { name: "editor.source" })).not.toBeInTheDocument();
+ expect(screen.getByText("Markdown", { exact: true })).toHaveAttribute("aria-label", "editor.markdown-mode");
expect(container.querySelector(".memo-editor-content")).toHaveAttribute("data-source-mode");
fireEvent.click(screen.getByRole("button", { name: "common.add" }));
fireEvent.click(screen.getByRole("menuitemcheckbox", { name: "editor.markdown-mode" }));
expect(sourceText(container)).toBeNull();
+ expect(screen.queryByText("Markdown", { exact: true })).not.toBeInTheDocument();
expect(localStorage.getItem(MODE_KEY)).toBe(JSON.stringify("rich"));
});
@@ -85,6 +86,7 @@ describe("MemoEditor source mode", () => {
const { container } = mount();
expect(sourceText(container)).not.toBeNull();
+ expect(screen.getByText("Markdown", { exact: true })).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "common.add" }));
expect(screen.getByRole("menuitemcheckbox", { name: "editor.markdown-mode" })).toHaveAttribute("aria-checked", "true");
});
diff --git a/web/tests/memo-editor-timestamps.test.tsx b/web/tests/memo-editor-timestamps.test.tsx
index 6652c92e2..35dec468c 100644
--- a/web/tests/memo-editor-timestamps.test.tsx
+++ b/web/tests/memo-editor-timestamps.test.tsx
@@ -13,7 +13,10 @@ vi.mock("@/connect", () => ({
attachmentServiceClient: { createAttachment: vi.fn() },
memoServiceClient: clients,
}));
-vi.mock("@/utils/i18n", () => ({ useTranslate: () => (key: string) => key }));
+vi.mock("@/utils/i18n", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("@/utils/i18n")>()),
+ useTranslate: () => (key: string) => key,
+}));
const originalCreate = new Date(2020, 0, 1, 10, 20, 30);
const originalUpdate = new Date(2020, 0, 2, 11, 22, 33);