Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(web): keep collapsed editor toolbar from leaking a second row

tianma-if023a4c7169a7
diff --git a/apps/web/src/components/EditorToolbar.tsx b/apps/web/src/components/EditorToolbar.tsx
index 5b6e7c8e..029a8e95 100644
--- a/apps/web/src/components/EditorToolbar.tsx
+++ b/apps/web/src/components/EditorToolbar.tsx
@@ -22,6 +22,7 @@ import {
ChevronUp,
} from "lucide-react";
import { cn } from "@/lib/utils";
+import { MEMO_EDITOR_TOOLBAR_COLLAPSED_CLASS_NAME } from "@/components/MemoEditorChromeDensity";
import { MemoEditorToolbarDivider, MemoEditorToolbarRow } from "@/components/MemoEditorToolbarChrome";
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from "@/components/ui/select";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
@@ -211,9 +212,13 @@ export const EditorToolbar = ({
const availableWidth = Math.max(0, controls.clientWidth - horizontalPadding);
const next = requiredWidth > availableWidth + 1;
const firstRowTop = Math.min(...visibleItems.map((item) => item.offsetTop));
+ const controlHeight = visibleItems.reduce((max, item) => Math.max(max, item.offsetHeight), 0);
+ const wrappedRowStart = firstRowTop + controlHeight * 0.75;
visibleItems.forEach((item) => {
- item.inert = !expanded && next && item.offsetTop > firstRowTop + 1;
+ const wrapped = !expanded && next && item.offsetTop >= wrappedRowStart;
+ item.inert = wrapped;
+ item.classList.toggle("invisible", wrapped);
});
setHasOverflow((current) => {
@@ -228,7 +233,10 @@ export const EditorToolbar = ({
return () => {
observer.disconnect();
Array.from(controls.children).forEach((child) => {
- if (child instanceof HTMLElement) child.inert = false;
+ if (child instanceof HTMLElement) {
+ child.inert = false;
+ child.classList.remove("invisible");
+ }
});
};
});
@@ -291,7 +299,7 @@ export const EditorToolbar = ({
ref={controlsRef}
className={cn(
hasOverflow && "pr-14 sm:pr-16",
- !expanded && "max-h-12 overflow-hidden"
+ !expanded && MEMO_EDITOR_TOOLBAR_COLLAPSED_CLASS_NAME
)}
>
{onMarkdownModeChange && (
diff --git a/apps/web/src/components/MemoEditorChromeDensity.ts b/apps/web/src/components/MemoEditorChromeDensity.ts
index 56e3382a..f56924dd 100644
--- a/apps/web/src/components/MemoEditorChromeDensity.ts
+++ b/apps/web/src/components/MemoEditorChromeDensity.ts
@@ -4,5 +4,9 @@ export const MEMO_EDITOR_TOP_ROW_CLASS_NAME =
export const MEMO_EDITOR_TOOLBAR_PADDING_CLASS_NAME =
"px-3 py-2 sm:px-4 sm:py-0.5";
+/** One control row: py-2 + h-8 on mobile, py-0.5 + h-8 on sm+. */
+export const MEMO_EDITOR_TOOLBAR_COLLAPSED_CLASS_NAME =
+ "max-h-12 overflow-hidden sm:max-h-9";
+
export const MEMO_EDITOR_TITLE_REGION_CLASS_NAME =
"space-y-1.5 px-4 pb-2.5 pt-2.5 sm:space-y-3 sm:px-7 sm:pb-4 sm:pt-4 lg:space-y-0 lg:px-10 lg:py-0";
diff --git a/apps/web/src/components/MemoEditorHeaderActions.test.mjs b/apps/web/src/components/MemoEditorHeaderActions.test.mjs
index 555a327b..d04f74b7 100644
--- a/apps/web/src/components/MemoEditorHeaderActions.test.mjs
+++ b/apps/web/src/components/MemoEditorHeaderActions.test.mjs
@@ -62,8 +62,11 @@ describe("shared memo editor header actions", () => {
expect(editorToolbarSource).toContain("<MemoEditorToolbarDivider");
expect(diagramToolbarSource).toContain("<MemoEditorToolbarDivider");
expect(toolbarChromeSource).toContain("MEMO_EDITOR_TOOLBAR_PADDING_CLASS_NAME");
+ expect(editorToolbarSource).toContain("MEMO_EDITOR_TOOLBAR_COLLAPSED_CLASS_NAME");
+ expect(editorToolbarSource).toContain('item.classList.toggle("invisible", wrapped)');
expect(densitySource).toContain("sm:min-h-9 sm:px-4 sm:py-0.5");
expect(densitySource).toContain("sm:px-4 sm:py-0.5");
+ expect(densitySource).toContain("max-h-12 overflow-hidden sm:max-h-9");
expect(densitySource.match(/MEMO_EDITOR_TOP_ROW_CLASS_NAME =\s*"([^"]+)"/)?.[1]).not.toContain("sm:px-7");
expect(densitySource.match(/MEMO_EDITOR_TOOLBAR_PADDING_CLASS_NAME =\s*"([^"]+)"/)?.[1]).not.toContain("sm:px-7");
expect(densitySource).toContain("lg:space-y-0 lg:px-10 lg:py-0");